简体   繁体   English

laravel & vue.JS:app.js 中的“组件”、“导入”和“使用”

[英]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? “组件”、“导入”、“使用”和“组件:{”到底在做什么?

  • 'component' probably defines the component file with the template. 'component' 可能用模板定义了组件文件。
  • 'import' -> I dont' know what that does. 'import' -> 我不知道那是做什么的。
  • 'use' -> also no idea. 'use' -> 也不知道。
  • 'components: {' -> probably makes the link back to the template file by passing the name of the component. 'components: {' -> 可能通过传递组件的名称使链接返回到模板文件。

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 中引入的。

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.

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