[英]laravel & vue.JS: 'component', 'import' and 'use' in app.js
I'm using laravel together with VueJS and I never entirely understood the logic behind the 'import', 'use' and 'component' used in app.js.我将 laravel 与 VueJS 一起使用,但我从未完全理解 app.js 中使用的“导入”、“使用”和“组件”背后的逻辑。 Maybe someone could give me a hint/link on how to use them correctly.
也许有人可以给我一个关于如何正确使用它们的提示/链接。
To use custom vue components (separate files) in a blade I need to define them in the root 'app.js' file.要在刀片中使用自定义 vue 组件(单独的文件),我需要在根“app.js”文件中定义它们。
Now here I'm kind of lost.现在我有点迷路了。 Inside the app.js file there are:
在 app.js 文件中有:
window.Vue = require('vue');
[..]
Vue.component('my-vue-component', require('./components/my-vue-component.vue').default);
[..]
import Vue from 'vue';
import VueDraggableResizable from 'vue-draggable-resizable';
[..]
Vue.use(VueClipboard);
as well as:也:
const app = new Vue({
el: '#app',
components: {
dropZone: vue2Dropzone,
draggable, Hooper, Slide, HooperPagination,
'my-vue-component': MyVueComponent,
[..]
},
What are 'component', 'import', 'use' and 'components:{' doing exactly? “组件”、“导入”、“使用”和“组件:{”到底在做什么?
1.import is not vue related. 1.import与vue无关。 Its function is to bring another js module into current js module.
它的 function 是在当前的 js 模块中引入另一个 js 模块。 If u know old js, it is similar to require(), it was introduced in es6.
如果你知道旧的 js,它类似于 require(),它是在 es6 中引入的。
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import
https://stackoverflow.com/questions/46677752/the-difference-between-requirex-and-import-x#:~:text=The%20major%20difference%20between%20require,act%20the%20same%20as%20require%20 . https://stackoverflow.com/questions/46677752/the-difference-between-requirex-and-import-x#:~:text=The%20major%20difference%20between%20require,act%20the%20same%20as%20require% 20 . this answer explained whats different between import and require.
这个答案解释了 import 和 require 之间的区别。
2.Vue.use is vue's feature, to install vue plugin. 2.Vue.use是vue的特性,用来安装vue插件。 Links below explained what's a vue plugin looks like and how to install it.
下面的链接解释了 vue 插件的外观以及如何安装它。
3.Vue.component and components both are the ways for vue to register vue component. 3.Vue.component 和 components 都是 vue 注册 vue 组件的方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.