Vue项目环境搭建

 

node   相当于   python
npm    相当于   pip
vue    相当于   django

 

 

 

1) 安装node,在官网下载好,然后在本地安装
官网下载安装包,傻瓜式安装:https://nodejs.org/zh-cn/

2) 换源安装cnpm
>: npm install -g cnpm --registry=https://registry.npm.taobao.org

3) 安装vue项目脚手架
>: cnpm install -g @vue/cli

注:2或3终端安装失败时,可以清空 npm缓存 再重复执行失败的步骤
npm cache clean --force

Vue项目创建

在cmd中创建

1) 先进入存放项目的目录(自己创建目录)
>: cd ***

2) 创建项目
>: vue create 项目名

3) 项目初始化,按照下面的选择

第四个选择第一条

Vue框架(三)——Vue项目搭建和项目目录介绍、组件、路由

 pycharm配置并启动vue项目

1.项目创建好后,用pycharm打开

2.添加配置npm启动

Vue框架(三)——Vue项目搭建和项目目录介绍、组件、路由

 Vue项目目录结构分析

├── v-proj
|    ├── node_modules      // 当前项目所有依赖,一般不可以移植给其他电脑环境
|    ├── public            
|    |    ├── favicon.ico    // 标签图标
|    |    └── index.html    // 当前项目唯一的页面
|    ├── src
|    |    ├── assets        // 静态资源img、css、js
|    |    ├── components    // 小组件
|    |    ├── views        // 页面组件
|    |    ├── App.vue        // 根组件
|    |    ├── main.js        // 全局脚本文件(项目的入口)
|    |    ├── router.js    // 路由脚本文件(配置路由 url链接 与 页面组件的映射关系)
|    |    └── store.js    // 仓库脚本文件(vuex插件的配置文件,数据仓库)
|    ├── README.md       //配置文件
└    └── **配置文件

Vue组件(.vue文件)

.vue文件由三大部分组成:template/script/style

# 1) template:有且只有一个根标签div
# 2) script:必须将组件对象导出 export default {}
# 3) style: style标签明确scoped属性,代表该样式只在组件内部起作用(样式的组件化)
//html代码:有且只有一个跟标签
<template> <div class="test"> </div> </template> // js代码:在export default {}的括号内完成组件的各项成员:data|methods|... <script> export default { name: "Test" } </script> // css代码:scoped样式化组件-样式只在该组件内部起作用 <style scoped> </style>

全局脚本文件main.js(项目入口)

import Vue from 'vue'    // node_modules下的依赖直接写名字
import App from './App.vue'     // ./代表相对路径的当前目录,文件后缀军可以省略
import router from './router'
import store from './store'

// 在main中配置的信息就是给整个项目配置
// 已配置 vue | 根组件App | 路由 | 仓库
// 以后还可以配置 cookie | ajax(axios) | element-ui

Vue.config.productionTip = false

new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app')

改写

import Vue from 'vue'  // 加载vue环境
import App from './App.vue'  // 加载根组件
import router from './router'  // 加载路由环境
import store from './store'  // 加载数据仓库环境

Vue.config.productionTip = false
new Vue({
    el: '#app',
    router,
    store,
    render: function (readFn) {
        return readFn(App);
    },
});
改写main.js

相关文章:

  • 2022-12-23
  • 2021-11-22
  • 2022-12-23
  • 2021-06-26
  • 2022-12-23
  • 2022-12-23
  • 2021-10-14
  • 2022-12-23
猜你喜欢
  • 2021-10-24
  • 2021-07-12
  • 2022-12-23
  • 2021-12-17
  • 2021-10-17
  • 2022-12-23
  • 2021-08-25
相关资源
相似解决方案