Vue常見問題及處理
- vue.js 2.0要求每個template只能有一個根元素。可以在最外層包一個div來解決這個問題。
vue.js:435 [Vue warn]: Error compiling template:
<h2>這是頁頭</h2> <button>登入</button>
Component template should contain exactly one root element. If you are using v-if on multiple elements, use v-else-if to chain them
instead.
解決方案:在最外邊 包上一個容器(不允許直接返回多個元素)
- 額
vue.js:435 [Vue warn]: Unknown custom element: <my-footer> - did you register the component correctly? For recursive components, make sure to provide the "name" option.
原因:你把區域性元件當成全域性元件去使用了
解決方案:
正確的註冊元件
3、 The "data" option should be a function that returns a per-instance value in component definitions.
原因:在元件中去初始化資料 不允許給data直接賦值一個物件
解決方案: Vue.component('',{
data:function(){ return {} } })
4、Uncaught TypeError: Cannot read property 'push' of undefined
原因:push前面的那個變數,其實undefined
解決方案:
this 通過箭頭函式來解決問題
5、ERROR in ./src/assets/img/favicon.ico
Module parse failed: C:xampphtdocsframeworkvueprojecttplssrcassetsimgfavicon.ico Unexpected character '' (1:0)
You may need an appropriate loader to handle this file type.
(Source code omitted for this binary file)
解決方案:找到build/webpack.base.conf.js
在41行加上 |ico
6、No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost :8080' is therefore not allowed access.
跨域問題