亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

嵌套/遞歸組件錯誤,未注冊組件

嵌套/遞歸組件錯誤,未注冊組件

千萬里不及你 2023-06-15 10:26:46
我正在嘗試將組件本身與 Nuxt.js 組件一起使用,但在使用中出現此錯誤:[Vue 警告]:未知自定義元素:- 您是否正確注冊了組件?對于遞歸組件,請確保提供“名稱”選項。我的代碼看起來像這樣components/MyComponent.vue<template><div>    <h1>{{ a.content }}</h1>    <MyComponent :child="a.child" /></div></template><script>export default {    data() {        return {            a : {},        }    },    mounted() {        axios.get('/api/blah/')        .then((res) =>        {            this.a = res.data;        })        .catch((err) =>        {            console.error(err);        });    }}</script>類似的代碼適用于帶有 vue.js 的原始單頁 html 頁面,不確定在此處使用之前如何命名組件。我如何讓它工作?
查看完整描述

1 回答

?
慕虎7371278

TA貢獻1802條經驗 獲得超4個贊

您應該為您的組件提供一個名稱以便遞歸地重用它,但您應該控制渲染以避免無限循環:


<template>

<div>

    <h1>{{ a.content }}</h1>

    <MyComponent :child="a.child" />

</div>

</template>


<script>


export default {

    name:"MyComponent",

    props:['child'],

    data() {

        return {

            a : {},

        }

    },

    mounted() {

        axios.get('/api/blah/')

        .then((res) =>

        {

            this.a = res.data;

        })

        .catch((err) =>

        {

            console.error(err);

        });

    }

}

</script>


查看完整回答
反對 回復 2023-06-15
  • 1 回答
  • 0 關注
  • 211 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號