在js开发中使用browserify等是非常新的。我也是Vue的新手。我想为我的应用程序创建额外的自定义组件。然而,我在很多方面都失败了,即使是在一步一步地学习不同的教程的时候。
这就是我现在得到的:
example.js
var MyComponent = Vue.extend({
data: function() {
return { message: 'This is a test' }
},
template: '{{ message }}'
});
Vue.component('my-component', MyComponent);
new Vue({
el: '#example'
});app.js
require('spark-bootstrap');
require('./../example.js');
require('./components/bootstrap');
require('./backoffice/main.js');
var app = new Vue({
mixins: [require('spark')]
});view.blade.php
<div id="example">
<my-component></my-component>
</div>gulpfile.js
elixir(function(mix) {
mix.less('app.less')
.browserify('app.js', null, null, { paths: 'vendor/laravel/spark/resources/assets/js' })
.copy('node_modules/sweetalert/dist/sweetalert.min.js', 'public/js/sweetalert.min.js')
.copy('node_modules/sweetalert/dist/sweetalert.css', 'public/css/sweetalert.css');
});我的错误
app.js:24638[Vue warn]: Unknown custom element: <my-component> - did you register the component correctly? For recursive components, make sure to provide the "name" option.发布于 2016-05-23 20:53:50
因为example.js是一个单独的模块,所以您也需要在该文件中导入Vue。我猜是你干的。但是,您也不希望在该文件中new一个Vue实例,因为稍后您已经在这样做了。如果<my-component>在星体内部,您已经有一个Vue应用程序在运行。
https://stackoverflow.com/questions/37399444
复制相似问题