template or render function not defined.

H_婷 关注

2018.08.16 17:22 字数 106 阅读 3859评论 0喜欢 2

下午写 Vue $parent 实例时,总是遇到这个问题,不禁让人陷入沉思

 
1.gif

Vue,醒醒啊,你怎么了,贴上子组件源代码

<template>
<div>
<child-component1></child-component1>
<child-component2></child-component2>
<button v-on:click="showChildComponentData">显示子组件的数据</button>
</div>
</template> <script>
export default{
components: {
'child-component1': {
template: '#child-component1',
data: function () {
return {
msg: 'child component 111111'
}
}
},
'child-component2': {
template: '#child-component2',
data: function () {
return {
msg: 'child component 222222'
}
}
}
},
methods: {
showChildComponentData: function () {
for (var i = 0; i < this.$children.length; i++) {
alert(this.$children[i].msg)
}
}
}
}
</script>

这是报错信息:

 
1.png

修改后的代码:

<template>
<div>
<child-component1></child-component1>
<child-component2></child-component2>
<button v-on:click="showChildComponentData">显示子组件的数据</button>
</div>
</template> <script>
export default{
components: {
'child-component1': {
template: '<p>I am ok</p>',
data: function () {
return {
msg: 'child component 111111'
}
}
},
'child-component2': {
template: '<p>ok</p>',
data: function () {
return {
msg: 'child component 222222'
}
}
}
},
methods: {
showChildComponentData: function () {
for (var i = 0; i < this.$children.length; i++) {
alert(this.$children[i].msg)
}
}
}
}
</script>

这样就好了,原因是 Vue 的构建,运行时构建删除了模板编译的功能,因此无法支持带 template 属性的 Vue 实例选项。

template or render function not defined.的更多相关文章

  1. template or render function not defined vue 突然报错了,怎么解决

    报错图例如下:template or render function not defined vue 突然报错了,怎么解决什么错误呢,就是加载不出来,网上看了一通,是vue版本不对,是vue-comp ...

  2. Failed to mount component: template or render function not defined.

    Failed to mount component: template or render function not defined. vue-loader13.0有一个变更就是默认启用了esModu ...

  3. "[Vue warn]: Failed to mount component: template or render function not defined"错误的解决

    VUE中动态路由出错: vue.esm.js?a026: [Vue warn]: Failed to mount component: template or render function not ...

  4. [Vue warn]: Failed to mount component: template or render function not defined. 错误解决方法

    解决方法import Vue from "vue"; 默认引入的文件是 vue/dist/vue.runtime.common.js.这个可以在node_modules/vue/p ...

  5. [Vue warn]: Failed to mount component: template or render function not defined.解决方案

    命名视图 vue router 里有一个 模式叫做 命名视图 本来一个页面里面只能有一个路由视图 对应 一个组件,现在可以多个路由视图 对应 多个组件. 出错点 点击标签之后,<router-v ...

  6. [Vue warn]: Failed to mount component: template or render function not defined. found in ---> <XFbwz> at src/views/XFbwz.vue <App> at src/App.vue <Root>

    1.引入.vue文件忘记加.vue 2.引入文件内容为空

  7. [Vue @Component] Control Template Contents with Vue's Render Function

    Declaring templates and elements inside of templates works great for most scenarios. Sometimes you n ...

  8. [AngularJS] ngModelController render function

    ModelValue and ViewValue: $viewValue: Actual string value in the view. $modelValue: The value in the ...

  9. vue实例属性之el,template,render

    一.el,template,render属性优先性当Vue选项对象中有render渲染函数时,Vue构造函数将直接使用渲染函数渲染DOM树,当选项对象中没有render渲染函数时,Vue构造函数首先通 ...

随机推荐

  1. SoapUI中读取Office365邮件

    常见邮件服务一般使用IMAP邮件访问协议,如果你所在公司更换到Office 365则需要另一个组件. Office 365使用的是Exchange Server电子邮件服务组件,需要微软的Jar包来支 ...

  2. HTTP协议 (一) HTTP协议详解

    当今web程序的开发技术真是百家争鸣,ASP.NET, PHP, JSP,Perl, AJAX 等等. 无论Web技术在未来如何发展,理解Web程序之间通信的基本协议相当重要, 因为它让我们理解了We ...

  3. DP专题之概率DP

    注意:在概率DP中求期望要逆着推,求概率要正着推 概率DP求期望: 链接: http://acm.hdu.edu.cn/showproblem.php?pid=4405 dp[ i ]表示从i点走到n ...

  4. [转]RF+Selenium2Library元素定位不到的问题

    原文地址:http://m.blog.csdn.net/m0_37553368/article/details/78016729 在基于RobotFramework框架使用Selenium2Libra ...

  5. Java-Maven:Maven百科

    ylbtech-Java-Maven:Maven百科 1.返回顶部 1. Maven项目对象模型(POM),可以通过一小段描述信息来管理项目的构建,报告和文档的软件项目管理工具.Maven 除了以程序 ...

  6. 转载:百为STM32开发板教程之十二——NAND FLASH

    http://bbs.21ic.com/icview-586200-1-1.html 百为STM32开发板教程之十二——NAND FLASH 参考资料:百为stm32开发板光盘V3\百为stm32开发 ...

  7. Windows 中属于不同Owner的Workspace 互相无法看见,且无法删除

    Windows 中属于不同Owner的Workspace 互相无法看见,且无法删除 而且不能重叠,重叠的话会报错,告诉你这个文件夹已经被其他用户映射, 所以你必须以那个Owner登陆tfs,然后删除 ...

  8. [Swift通天遁地]一、超级工具-(2)制作美观大方的环形进度条

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  9. CocoaPods 升级出现问题 (一)

    升级了cocoapods 然后出现了这个问题 , 一上午时间各种FQ啊 ,终于吃完饭后找到原因了 ,OK 开工

  10. Codeforces Round #459 (Div. 2)C. The Monster

    C. The Monster time limit per test 1 second memory limit per test 256 megabytes input standard input ...