在Laravel 5.3.10 + Vue.js 2.0.1上出现“Failed to mount component”
"Failed to mount component” error on Laravel 5.3.10 + Vue.js 2.0.1
我一直在开发Laravel + Vue.js。我想开发Vue组件到Laravel刀片模板,但是当我尝试这样做时,发生了以下错误,并且它不能很好地工作。
*为了检查,我只写了一个最小的Vue组件代码。
https://github.com/vuejs/vue-loader/issues/287
正在发生的问题和错误信息
[Vue warn]: Failed to mount component: template or render function not defined. (found in anonymous component - use the "name" option for better debugging messages.)
index.blade.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<div id="app"></div>
<script src="js/bundle.js"></script>
</body>
</html>
app.js
import Vue from 'vue'
import InputText from './components/InputText.vue'
new Vue({
render(h) {
return h(InputText)
}
}).$mount('#app')
InputText.vue
<template>
<input class="input-text" type="text">
</template>
<script>
export default {
}
</script>
<style lang="sass" scoped>
</style>
gulp.file.js
const elixir = require('laravel-elixir');
require('laravel-elixir-vue-2');
elixir(mix => {
mix.sass('**/*.scss')
.webpack('')
});
webpack.config.js
const webpack = require('webpack');
module.exports = {
entry: {
bundle: './resources/assets/js/app.js',
},
output: {
filename: '[name].js',
},
resolve: {
root: __dirname,
extensions: ['', '.js', '.vue'],
modulesDirectories: ['node_modules'],
alias: {
vue: 'vue/dist/vue.js',
},
},
module: {
loaders: [
{
test: /'.vue?$/,
loader: 'vue-loader',
},
{
test: /'.js$/,
loader: 'babel',
exclude: /node_modules/,
},
{
test: /'.html$/,
loader: 'vue-html',
},
{
test: /'.(jpg|png)$/,
loader: 'url-loader?limit=10000',
},
],
},
vue: {
loaders: {
scss: 'style!css!sass',
},
},
};
package.json
"devDependencies": {
"babel-core": "^6.17.0",
"babel-loader": "^6.2.5",
"babel-plugin-transform-runtime": "^6.15.0",
"babel-preset-es2015": "^6.16.0",
"babel-runtime": "^6.11.6",
"laravel-elixir": "^6.0.0-11",
"laravel-elixir-browsersync-official": "^1.0.0",
"laravel-elixir-vue-2": "^0.2.0",
"laravel-elixir-webpack-official": "^1.0.6",
"vue": "^2.0.1",
"vue-loader": "^9.5.1",
"webpack": "^1.13.2"
...
}
互补信息 Laravel 5.3.10
node . js 6.4.0
NPM 3.9.3
您需要注册InputText组件,以便在根组件中使用它。这里使用的是ES2015的简写。
import Vue from 'vue'
import InputText from './components/InputText.vue'
new Vue({
components: {
InputText
},
render(h) {
return h(InputText)
}
}).$mount('#app')
在您的webpack.config.js
中vue
下的loaders
旁边添加esModule: true
,您应该很好。
或者,您可以使用const Vue = require('vue')
代替import Vue from 'vue'
,它试图从组件生成的模块中加载default
导出,并且它无法这样做,除非您告诉vue-loader生成兼容的代码。
实际上这是规范之间更普遍的不兼容,其中export default foo
并不意味着与module.exports = foo
相同。当您将前者require
时,它将给您一个对象{ default: foo }
,而后者将返回未封装的foo
。
相关文章:
- XMLHttpRequest无法加载-文件footer.html, "Error: Failed to exe
- 未捕获DOMException: Failed to execute 'on 'FileReader
- React Router: Failed to Navigate Route
- 未捕获类型错误:Failed to execute 'appendChild'on 'Node&
- 未捕获的SecurityError: Failed to execute 'replaceState'&
- 尝试调用另一个peer时PeerJS错误:Failed to execute 'addStream'on
- Systrace错误.未捕获的SecurityError: Failed to execute 'pushSta
- 在Laravel 5.3.10 + Vue.js 2.0.1上出现“Failed to mount component”
- 未捕获的SecurityError: Failed to execute 'replaceState'o
- 未捕获类型错误:Failed to execute 'appendChild'on 'Node&
- 为什么我得到错误“Uncaught SecurityError: Failed to execute 'toDa
- 未捕获的NetworkError: Failed to execute 'importScripts'&
- Suppress "WebSocket connection to 'xyz' failed&
- InvalidStateError: Failed to execute 'dispatchEvent'
- 未捕获的TypeError: Failed to execute 'insertBefore'on
- 未捕获NotFoundError: Failed to execute 'appendChild'on
- 为Angular JS启用html5模式会抛出JS错误:Failed to instantiate module due
- TypeError: Failed to execute 'appendChild'on 'No
- OpenLayers: 'Failed to execute 'toDataURL' on
- 未捕获的SecurityError: Failed to set the 'domain'propert