Vue模板或渲染功能尚未定义我既不使用? [英] Vue template or render function not defined yet I am using neither?

查看:324
本文介绍了Vue模板或渲染功能尚未定义我既不使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的主要javascript文件:

This is my main javascript file:

import Vue from 'vue'

new Vue({
  el: '#app'
});

我的HTML文件:

<body>
    <div id="app"></div>

    <script src="{{ mix('/js/app.js') }}"></script>
</body>

带有运行时构建的Vue.js的Webpack配置:

Webpack configuration of Vue.js with the runtime build:

alias: {
    'vue$': 'vue/dist/vue.runtime.common.js'
}

我仍然得到这个众所周知的错误:

I am still getting this well known error:


[Vue警告]:无法安装组件:未定义模板或渲染功能。
(在根实例中找到)

[Vue warn]: Failed to mount component: template or render function not defined. (found in root instance)

为什么我的#app div里面什么都没有在我安装Vue的地方,我仍然收到渲染/模板错误?它说在中找到了,但没有找到任何东西,因为它甚至没有任何内容?

How come when I don't even have a single thing inside my #app div where I mount Vue, I am still getting a render/template error? It says found in root but there is nothing to be found because it does not even have any content?

如何如果这不起作用,我想安装吗?

How am I suppose to mount if this does not work?

编辑:

我试过这样似乎有用:

new Vue(App).$mount('#app');

这是有道理的,因为使用 el 属性意味着你正在扫描任何组件的dom元素并且它没用,因为运行时构建没有编译器。

It make sense because using the el property implies you are 'scanning' that dom element for any components and it's useless because the runtime build does not have a compiler.

仍然是一个非常奇怪的错误消息,特别是当我把整个#app div清空时。

Still it is an extremely strange error message to throw, especially when I have my entire #app div emptied out.

希望有人能证实我的想法。

Hopefully somebody could confirm my thoughts.

推荐答案

您收到该错误的原因是您正在使用运行时构建,它不支持HTML文件中的模板,如此处所示 vuejs.org

The reason you're receiving that error is that you're using the runtime build which doesn't support templates in HTML files as seen here vuejs.org

从本质上讲,加载vue文件的原因是它们的模板编译时转换为渲染函数,而你的基本函数试图从你的html元素编译。

In essence what happens with vue loaded files is that their templates are compile time converted into render functions where as your base function was trying to compile from your html element.

这篇关于Vue模板或渲染功能尚未定义我既不使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆