如何在 symfony 4 中使用单个文件 vue 组件?

How can I use single file vue component with symfony 4?

我想做的是: 1) 在 app.js 中可以使用

import Vue from 'vue'
import Time from './vue/components/Time'

Vue.component('vue-time', {
    template: '<span class="foo bar">Hi</span>'
})

new Vue({
    el: 'header',
    components: { Time }
})

2) 在 Time.vue 中:

<template>
    <div>current time</div>
</template>

<script>
    module.exports = {

    }
</script>

<style>
</style>

这可能吗?所有这些都是使用 encore-webpack 和 symfony4 实现的。 谢谢

app.js中注册了2个组件:

  1. 时间 - 本地注册
  2. vue-time - 全局注册

如果你想注册 Time global 添加 app.js this:

*不要使用名称 Time https://developer.mozilla.org/uk/docs/Web/HTML/Element/time

Vue.component(`Time`, Time)

app.js中删除:

components: { Time }

然后在您的应用程序的任何地方使用标签 <time></time>