iview 3.0.0 按需引入的bug

iview 3.0.0 按需引入的bug

官網教程 https://www.iviewui.com/docs/... 簡單易懂css

圖片描述

按照官網擼完會再在咱們的項目中引入你須要的組件(好比button),會發現報以下錯:
Cannot read property 'size' of undefinedvue

這是爲何呢,都是按照官網一手一腳碼的,這時候咱們須要懷疑的精神,直接打開
node_modules/iview/src/components/button/這個文件夾,看看button.vue這裏的源碼而後找到props.size的undefault方法,將this.$IVIEW打印出來,你就會發現緣由所在
圖片描述node

這個this.$IVIEW 打印出來是undefined,這個就能夠解析上面Cannot read property 'size' of undefined的報錯了iview

解決辦法

在入口js(main.js)上本身手動給vue.$IVIEW綁定一個空對象ide

import 'iview/dist/styles/iview.css';

import { Button, Table } from 'iview';
Vue.component('Button', Button);
Vue.component('Table', Table);
//手動給綁定個空對象,就不會報錯了
Vue.prototype.$IVIEW = {}
相關文章
相關標籤/搜索