首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Laravel火花中使用Vue自定义组件

在Laravel火花中使用Vue自定义组件
EN

Stack Overflow用户
提问于 2016-05-23 19:55:55
回答 1查看 1K关注 0票数 0

在js开发中使用browserify等是非常新的。我也是Vue的新手。我想为我的应用程序创建额外的自定义组件。然而,我在很多方面都失败了,即使是在一步一步地学习不同的教程的时候。

这就是我现在得到的:

example.js

代码语言:javascript
复制
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

代码语言:javascript
复制
require('spark-bootstrap');

require('./../example.js');

require('./components/bootstrap');

require('./backoffice/main.js');

var app = new Vue({
    mixins: [require('spark')]
});

view.blade.php

代码语言:javascript
复制
<div id="example">
    <my-component></my-component>
</div>

gulpfile.js

代码语言:javascript
复制
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');
});

我的错误

代码语言:javascript
复制
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.
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-05-23 20:53:50

因为example.js是一个单独的模块,所以您也需要在该文件中导入Vue。我猜是你干的。但是,您也不希望在该文件中new一个Vue实例,因为稍后您已经在这样做了。如果<my-component>在星体内部,您已经有一个Vue应用程序在运行。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37399444

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档