
我想把store.js整合,使其能通过Vue.localstore和 this.$localstore调用
但是却报错: 
插件代码如下:
import store from "store"; (function(){ function install(Vue){ Object.defineProperty(Vue.prototype, '$localstore',{ get(){ return { get(key){ return store.get(key); }, set(key,value){ return store.set(key,value); }, remove(key){ return store.remove(key); } } } }); } if (typeof exports == "object") { module.exports = install } else if (typeof define == "function" && define.amd) { define([], function(){ return install }) } else if (window.Vue) { Vue.use(install) } })() 调用代码如下:
import VueStore from './plugins/localstore.js'; Vue.use(VueStore); Vue.localstore.get('token'); 1 ChiangDi 2016-10-04 15:59:04 +08:00 via Android 直接用原来的不好吗。。。都有模块系统了,为什么要把它挂在 Vue 下面?? |
4 learnshare 2016-10-04 16:49:21 +08:00 @ZGLHHH 每个组件 import 一次,不正是组件化的好处么? |
5 ZGLHHH OP |
7 learnshare 2016-10-04 18:04:09 +08:00 @SourceMan 是的,模块只引入一次,多处引用 |
8 ZGLHHH OP |