所以我有一个有按钮的页面。单击此按钮时,我希望文本出现,每次单击该按钮时,我都希望文本显示如下:

这是我的密码:
<v-row>
<component
v-for="(component, index) in components"
:key="index"
:is="component"/>
</v-row>
<v-row justify="left" class="ml-3">
<v-btn class="elevation-7 grey darken-1 btn" @click="add">Click me</v-btn>
</v-row>
<script>
import Vue from 'vue'
Vue.component('component', {
template: '<p>component</p>'
})
export default {
data: () => {
return {
components: [Comp]
};
},
methods: {
add: function () {
this.components.push(Comp)
}
}
}
</script>然而,当我点击按钮时,什么都没有出现?我真的很想得到一些帮助,因为我不明白这一点。
更新
我检查了控制台,我看到了这个:
[Vue warn]: You are using the runtime-only build of Vue where the template compiler is not available. Either pre-compile the templates into render functions, or use the compiler-included build.然后,此错误指向this.components.push(Comp)。在vue.config.js中,我添加了runtimeCompiler: true,但是这个错误仍然存在,文本没有出现。
这都是在vuejs +电子上完成的。
发布于 2021-08-25 01:22:18
似乎您正在使用vue2。
因为编译器不包含在仅运行时构建中,所以必须为vue设置别名。
// if you are using webpack
build: {
extend(config, ctx){
config.resolve.alias['vue'] = 'vue/dist/vue.common';
}
},
// if you are using vite
vite: {
resolve: {
alias: {
'vue': 'vue/dist/vue.common'
}
},
}有关更多详细信息,请查看docs:运行时+编译器与运行时专用
https://stackoverflow.com/questions/68915256
复制相似问题