简体   繁体   English

如何在laravel中将Vue组件添加到文件app.js中?

[英]How to add a Vue component to the file app.js in laravel?

I was watching a tutorial that uses laravel and vue and on the tutorial he add a vue component in the components folder and then register that component in app.js file using this code 我正在看一个使用laravel和vue的教程,在该教程中,他在组件文件夹中添加了一个vue组件,然后使用此代码将该组件注册到app.js文件中

Vue.component('articles',require('./components/articles.vue');

And it works fine and in my case when I use this code it says require is not defined . 而且它工作正常,在我的情况下,当我使用此代码时,它说require is not defined In the app.js file theres already an example component registered using this code app.js文件中,已经有使用此代码注册的示例组件

Vue.component('example-component',__webpack_require__(37));

My question is how does the number 37 define the ExampleComponent.vue file? 我的问题是数字37如何定义ExampleComponent.vue文件? And how can I get the number of the file i want to include? 以及如何获取要包含的文件编号? And I don't have the webpack CLI Thanks 而且我没有webpack CLI

看来我在公共目录中使用了错误的app.js文件,应该将这些代码添加到位于组件目录中的app.js中

You should try 你应该试试

import YourComponent from 'path';
new Vue({

  components: {
   "your-component": YourComponent

});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM