Vue 模板或渲染函数尚未定义,我都没有使用? [英] Vue template or render function not defined yet I am using neither?

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

问题描述

这是我的主要 javascript 文件:

This is my main javascript file:

import Vue from 'vue'

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

我的 HTML 文件:

My HTML file:

<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 的地方甚至没有任何东西时,我仍然收到渲染/模板错误?它说 found in root 但什么也找不到,因为它甚至没有任何内容?

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天全站免登陆