[英]VueJS - calling method in v-for loop, get error 'not defined on the instance but referenced during render'
[英]vuejs dynamic component throw error for v-bind:is, error is Property or method … is not defined on the instance but referenced during render
文件中的代碼:
<template>
<component v-bind:is="bbc"></component>
</template>
<script>
import bbc from './bbc.vue';
export default {
name: 'ShowRoom2',
};
</script>
./bbc.vue
<script>
export default {
name: 'bbc',
props: {
msg: String,
},
mounted() {
console.log('bbc is mounted');
},
render() {
if (this.func) this.func();
return (
<div class="bbcMyClass">
<h1>bbc: <span>Pal</span> <span>{this.msg}</span></h1>
</div>
)
}
};
</script>
重現
src/components/ShowRoom2.vue
是的,模板中的作用域與腳本作用域不同。 如果需要一些數據,則需要在代碼的“組件”定義部分內聲明它們。 對於您的情況,我猜想'data'屬性應該起作用
import bbc from './bbc.vue';
export default {
name: 'ShowRoom2',
data() {
return {
bbc: bbc,
};
},
};
但是,代碼的模板部分也看起來很奇怪。 您能解釋一下您要做什么嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.