小结


最近开发的过程中遇到一些之前没有遇到过的写法,记录一下。

  1. 使用 install 方法写一个插件,全局使用。
import table from './src/table';

/* istanbul ignore next */
table.install = function(Vue) {
  Vue.component(table.name, table);
};

export default table;

main.js 中引入一次

import Vue from 'vue'
import defaultTable from '@/components/table'

Vue.use(defaultTable)
  1. main.js中new Vue的写法
...

new Vue({
  el: '#app',
  store,
  data: {
    busEvent: new Vue() //用于组件通信
  },
  router,
  components: { App },
  template: '<App/>',
  created() {
    this.getLoginInfo()
  },
  methods: {
    getLoginInfo(){
      this.$get('./admin/getUserInfo').then(res => {
        this.$store.commit('setStateCommon', {key: 'user', value: res})
        this.$store.dispatch('updateMenulist', {userName: res.userName, userId: res.userId})
      })
    }
  }
})
  1. 添加Vue方法实例 ``` js import echarts from ‘echarts’

Vue.prototype.$echarts = echarts

// 其他页面调用 this.$echarts.xxx ```


js

94 Words

2019-11-26 11:16 +0000