初始化 NPM VUE-CLI 之前的文章有提到过
起名字起成 vision
vue create vision
Vuex、Router、Less预处理、
取消选择:
ESE 测试 单元测试 ES-lint
创建完成后显示的是基础欢迎页 把无关的代码删除 只留下最干净的页面
app.vue
- <template>
- <div id="app">
- <router-view/>
- div>
- template>
- <style lang="less">
- style>
router/index.js
后期需要新增展示、引入import 对应的组件 在下方路由表注册即可
- import Vue from 'vue'
- import VueRouter from 'vue-router'
- const Screen = () => import('../Screen')
-
- Vue.use(VueRouter)
-
- const routes = [
- {
- path: '/',
- redirect:'/screen'
- },
- ]
-
- const router = new VueRouter({
- routes
- })
-
- export default router
这里我们在 public/index.html 外部引入 好处:项目上线时 减少体积 (为了稳定这里先用本地的 打包时再修改)
main.js:
// 全局挂载 echarts 任意组件就可以使用 this.$echarts Vue.prototype.$echarts = window.echarts
直接使用npm 安装的话 后期为了节省体积 还是要进行外联
安装指令:
npm install echarts --savemain.js:
import * as echarts from 'echarts';
npm install axios
main.js:
使用 node express 创建一个本机服务端口 2903
// axios 的配置封装 axios.defaults.baseURL = 'http://127.0.0.1:2903/api/' // 全局挂载 axios 任意组件就可以使用 this.$http Vue.prototype.$http = axios
直接写在App.vue里了 原则就是将所有的容器的宽度和高度设置为占满父容器
- <template>
- <div id="app">
- <router-view/>
- div>
- template>
-
- <style lang="less">
- html,body,#app,.comP1,.comP2,.comP3{
- width: 100%;
- height: 100%;
- margin: 0;
- padding: 0;
- overflow: hidden;
- position: relative;
- }
- canvas{
- border-radius: 24px;
- }
- style>
store/inedx.js
- import Vue from 'vue'
- import Vuex from 'vuex'
-
- Vue.use(Vuex)
-
- export default new Vuex.Store({
- state: {
- theme:'chalk'
- },
- getters: {
- },
- mutations: {
- changeTheme(state){
- if (state.theme === 'chalk'){
- state.theme = 'vintage'
- }else {
- state.theme = 'chalk'
- }
- }
- },
- actions: {
- },
- modules: {
- }
- })
main.js:
- import Vue from 'vue'
- import App from './App.vue'
- import router from './router'
- import store from './store'
- import axios from "axios";
-
-
- // axios 的配置封装
- axios.defaults.baseURL = 'http://127.0.0.1:2903/api/'
- // 全局挂载 axios 任意组件就可以使用 this.$http
- Vue.prototype.$http = axios
-
- import './assets/font/iconfont.css'
-
- import * as echarts from 'echarts';
-
- // 全局挂载 echarts 任意组件就可以使用 this.$echarts
- Vue.prototype.$echarts = window.echarts
-
-
- Vue.config.productionTip = false
-
- new Vue({
- router,
- store,
- render: h => h(App)
- }).$mount('#app')