有2個由vue-cli生成的項目。爲什麼在Vue中require()方法後需要默認?
它的一個我可以添加像下面這段代碼組件:
Vue.component('HeaderBar',require("./components/common/HeaderBar.vue"));
但是另外一個,我不能做到這一點,我必須像這樣的代碼:
Vue.component('HeaderBar',require("./components/common/HeaderBar.vue").default);
如果不是,我會收到此錯誤信息:
Failed to mount component: template or render function not defined
有人可以告訴我爲什麼會這樣?
謝謝你的幫助。
非常感謝!另一個問題是,爲什麼第一個項目我可以要求沒有默認屬性的組件? –
我想這樣做,但我沒有足夠的聲譽:( –