laravel 中如何使用vue组件

laravel 5.5框架中,想使用vue组件

1.在app.js中定义

window.Vue = require('vue');
new Vue({//实例化Vue
    el: '#apps'
});
Vue.component(
    'but',
    require('./components/button.vue')
);

2.在页面中引入

@extends('common.app')

@push('styles')
@endpush

@push('scripts')
<script type="text/javascript"></script>
@endpush

@section('appContent')
<div id="apps">
  <but></but>
</div>
@endsection

3.webpack.mix.js中

mix.setPublicPath('public/');
mix.setResourceRoot('../');
mix.js('resources/assets/js/app.js', 'public/js');

使用的时候也打包了的,结果在页面中报错
image.png

app.js?v=1.0.0:38827 [Vue warn]: Unknown custom element: <but> - did you register the component correctly? For recursive components, make sure to provide the "name" option.

(found in <Root>)

不知道这是啥情况???

阅读 2.4k
1 个回答

你是否引入了 public/app.jspublic/app.css 呢?然后是否进行了重新打包呢?

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题