【问题标题】:How can I use single file vue component with symfony 4?如何在 symfony 4 中使用单文件 vue 组件?
【发布时间】:2017-12-22 18:51:12
【问题描述】:

我想做的是: 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 实现。 谢谢。

【问题讨论】:

  • 没有理由不这样做。 Symfony4 与否,一切都是关于 webpack 为您正确地转译资产。
  • 嗨,如果我想从 Vue 文件加载组件怎么办?

标签: symfony vue.js vuejs2 webpack-encore


【解决方案1】:

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

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

如果你想注册 Time 全局添加 app.js 这个:

*不要使用名字Timehttps://developer.mozilla.org/uk/docs/Web/HTML/Element/time

Vue.component(`Time`, Time)

app.js 中删除:

components: { Time }

然后在应用程序的任何地方使用标签&lt;time&gt;&lt;/time&gt;

【讨论】:

  • 您好,看来问题出在我不知道的时间标签上。奇怪。
猜你喜欢
  • 1970-01-01
  • 2018-11-01
  • 2017-05-29
  • 1970-01-01
  • 1970-01-01
  • 2018-03-05
  • 2020-01-18
  • 2017-12-20
  • 2019-09-14
相关资源
最近更新 更多