[英]Vue2 + laravel6 - Component implementation
我刚开始将 Vue2 与 Laravel6 一起使用,并在尝试了解如何使用组件方法时卡住了。
由于我是 Vue 的新手,所以我使用 Vue 的官方教程作为参考。 我从这里( https://v2.vuejs.org/v2/guide/components.html )学到的关于 Vue 组件实例化的知识是我们为组件提供选项。(例如,我们为 Z4C4ZDBpart.FCAED0038A 提供“模板:”选项。C)
当我查看 resouces resouces/js/app.js
的 laravel6 代码时,它看起来像这样:
Vue.component('example-component', require('./components/ExampleComponent.vue').default);
我查看了js/components/ExampleComponent.vue
期望看到在那里声明的一些选项。 但是,ExampleComponent.vue 文件中没有选项。 相反,我看到<template></template>
标记。 显然, <template></template>
标记似乎可以用作“模板:”选项。
关于上述问题,我有两个问题:
<template></template>
标签是否与 'template:' 选项具有相同的含义?<props></props>
标记用于 'props:' 选项吗?或<data></data>
标记用于 'data:' 选项?提前致谢!
在Vue
世界中,定义component
有两种流行的类型
在这种类型中,您将所有HTML
添加到template
属性中,并将props
添加为component
object 中的attribute
Vue.component('button-counter', {
data: function () {
return {
count: 0
}
},
template: '<button v-on:click="count++">You clicked me {{ count }} times.</button>'
})
在这种类型中,您将component
逻辑添加到以.vue
结尾的单独文件中,例如在laravel
中有一个ExampleComponent.vue
文件,您会在上面找到它只是template
标签,只是作为组件内容的包装器,您可以编写它的逻辑如下所述。
<template>
// some content here
</template>
<script>
export default {
props: [],
methods: {
},
data(){
return {
}
}
}
</script>
没有称为props
或data
的标签
欲了解更多信息,请阅读这篇文章
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.