Javascript &引用;未能安装组件”;Laravel 5.3.10和x2B上的错误;Vue.js 2.0.1
我一直在研究Laravel+Vue.js。 我想在Laravel刀片模板上开发Vue组件, 但是当我尝试这样做时,出现了以下错误,并且效果不好。Javascript &引用;未能安装组件”;Laravel 5.3.10和x2B上的错误;Vue.js 2.0.1,javascript,laravel-5,vue.js,Javascript,Laravel 5,Vue.js,我一直在研究Laravel+Vue.js。 我想在Laravel刀片模板上开发Vue组件, 但是当我尝试这样做时,出现了以下错误,并且效果不好。 *为了便于检查,我只编写了Vue组件的最少量代码 参考以下文章,我尝试了各种方法。 正在发生的问题和错误消息 [Vue warn]: Failed to mount component: template or render function not defined. (found in anonymous component - use the "
*为了便于检查,我只编写了Vue组件的最少量代码 参考以下文章,我尝试了各种方法。
正在发生的问题和错误消息
[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
InputText.vue
webpack.config.js
package.json
补充资料
拉威尔5.3.10Node.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')
您需要注册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'
,后者尝试从组件中从生成的模块加载默认值
导出,但无法执行此操作,除非您告诉Vue加载程序生成兼容的代码
实际上,这是规范之间更普遍的不兼容,其中export default foo
并不意味着与module.exports=foo
相同。当您require
前者时,它将给您一个对象{default:foo}
,而后者将返回foo
未封装
这就是为什么您必须告诉vue loader您是否正在使用这两个规范。在
webpack.config.js
中的loaders
下添加esModule:true
,您应该可以开始了
或者,您可以使用const Vue=require('Vue')
而不是import Vue from'Vue'
,后者尝试从组件中从生成的模块加载默认值
导出,但无法执行此操作,除非您告诉Vue加载程序生成兼容的代码
实际上,这是规范之间更普遍的不兼容,其中export default foo
并不意味着与module.exports=foo
相同。当您require
前者时,它将给您一个对象{default:foo}
,而后者将返回foo
未封装
这就是为什么您必须告诉vue loader您是否正在使用这两种规格。您是否曾经使用过它?您是否曾经使用过它?
<template>
<input class="input-text" type="text">
</template>
<script>
export default {
}
</script>
<style lang="sass" scoped>
</style>
const elixir = require('laravel-elixir');
require('laravel-elixir-vue-2');
elixir(mix => {
mix.sass('**/*.scss')
.webpack('')
});
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',
},
},
};
"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"
...
}
import Vue from 'vue'
import InputText from './components/InputText.vue'
new Vue({
components: {
InputText
},
render(h) {
return h(InputText)
}
}).$mount('#app')