Vue插件
介绍插件就是给Vue添加全局功能 install vue插件应该暴露一个install方法。此方法调用时,将Vue构造函数作为第一个参数传入,以及将一个可选的选项作为第二个参数传入 Plugin.install = function(Vue, options) { // 1. 添加全局方法或属性 Vue.myGlobalMethod = function () { // 一些逻辑…… } // 2. 添加一个全局资源(asset) Vue.directive('my-directive', { bind (el, binding, vnode, oldVnode) { // 一些逻辑…… } ... }) // 3. 注入一..
更多vuex
Vuex 通过 store 选项,提供了一种机制将状态从根组件“注入”到每一个子组件中(需调用 Vue.use(Vuex)) State 主状态树 const state = { count:10, todoList: [ {id: 1;done: true}, {id: 2;done: false} ] } <!-- 获取 --> store.state.count <!-- 实例获取 --> this.$store.state.count Getter 通过 State派生出来的状态 const getter = { // 获取state里todoList长度 gettoListLength: s..
更多