Vue入門之旅:一報錯 Unknown ... make sure to provide the "name" option及error compiling template


報錯一: Unknown custom element: <custom-select> - did you register the component correctly? For recursive components, make sure to provide the "name" option

代碼:

html

<custom-select v-bind:list="list2"></custom-select>

 

js

new Vue({
    el: "#app",
    data:{
        list1: [{"name":"beijing"}, {"name" : "hangzhou" }],
        list2: ["2017-1-1", "2017-3-3"]
    }
});
//<li class="match-list-li">'+value.name+'</li>
Vue.component("custom-select", {
    data: function(){
        return {
            selectShow : false,
            val: ""    
        };
    },
    props: ["list"],
    template: `
            <input type="text" class="form-control" placeholder='press "enter" to match the Employee'
             @click="selectShow = !selectShow"    
             :value="val">    
         
              <match-list v-show="selectShow"
                           :list="list"
                          v-on:received="changeValueHandler"
               ></match-list>  
          
            
        `,
    methods : {
        //v-on:received 訂閱事件
        changeValueHandler(value){
            this.val = value;

        }
    }
});
//child
Vue.component("match-list", {
    props: ["list"],
    template: `
            <ul class="repo-admin-match">
                <li class="match-list-li" v-for="item of list" @click="changeValueHandler(item)">{{item}}</li>
            </ul>
        `,
    methods : {
        changeValueHandler : function(name){
            //在子組件中有交互
            //告知父級 改變val 需發出一個自定義事件
            this.$emit("received", name);
        }
    }
});

報錯原因:

先新建了Vue(new Vue),然后注冊組件(Vue.component) 。把順序顛倒一下即可解決

------------------------------------

報錯2:error compiling template

這個一般是寫的不符合規范,不能被編譯

--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.大意應該是Component template應該包含一個確切存在的根元素

所以 我用<section class="wrap"></wrap>包裹起來


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



猜您在找 vue報錯[Vue warn]: Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the "name" option. vue引入組建報錯Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the "name" option. found in VUE報錯解決方法 Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the "name" option. at src/views/index/"> [Vue warn]: Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the "name" option. found in ---> at src/views/index/ [Vue warn]: Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the "name" option.問題的解決方法 使用el-dialog時,報錯“Unknown custom element: did you register the component correctly?...make sure to provide the 'name' option” vue組件注冊錯誤:Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the "name" option. Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the "name" option. found in ]: Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the "name" option.解決方法 Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the "name" option.
 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM