最近想把以前做的一個組件封裝成插件,用下面的代碼封裝:import Mycom from './mycomponent'const plugin = {install (Vue, opitions) {var ele = '.className'if (ele) {const Com = Vue.extend(Mycom)const Lcom = new Com({propsData: {a: opitions.a,b: opitions.b}})setTimeout(() => {Lcom.$mount(ele)}, 0)}}}if (typeof window !== 'undefined' && window.Vue) {window.Vue.use(plugin)}export default plugin其他代碼都沒問題,就是window.Vue.use(plugin)怎么把參數(shù)a,b傳進去?。?
1 回答

慕蓋茨4494581
TA貢獻1850條經(jīng)驗 獲得超11個贊
可以通過vuex完成組件之間的傳參,包括數(shù)組對象等,這也是作者建議的做法,構建大型項目管理的狀態(tài)過多不可能都通過url的方式傳遞參數(shù)的。
用了vue-router就是單頁app,頁面都沒刷新過,你把變量放在 window. 所有組件都能訪問得到。
- 1 回答
- 0 關注
- 1874 瀏覽
添加回答
舉報
0/150
提交
取消