【问题标题】:Require .vue single file component in PHP app在 PHP 应用程序中需要 .vue 单文件组件
【发布时间】:2018-10-14 15:26:56
【问题描述】:

我正在尝试在我的 php 应用程序中需要一个 .vue 单文件组件,但如果没有内联模板方法,我无法使其工作。 因此,由于我没有节点 main.js 来导入 Vue 并要求组件,我如何要求我的 .vue 或已编译的 .js 组件进行组件注册?

工作组件注册:

Vue.component('example-component', ({
    template: "<div>The component template</div>"
}));

不工作

Vue.component('example-component', require('./components/js/ExampleComponent.vue'));

谢谢!

【问题讨论】:

    标签: javascript php vue.js vue-component


    【解决方案1】:

    试试这个:

    Vue.component('example-component', require('./components/js/ExampleComponent.vue').default);
    

    【讨论】:

    • 感谢您的回复,但我收到了相同的错误消息:Uncaught ReferenceError: require is not defined
    • 您尝试在浏览器中运行?检查这个:stackoverflow.com/questions/19059580/…
    • 哦,你是对的,太失败了。但是我已经尝试将 .vue 单个文件组件传递给 webpack vue-loader,当我包含编译后的 .js 文件时,我收到错误:Unknown custom element: - 你注册了组件吗正确吗?对于递归组件,请确保提供“名称”选项。
    猜你喜欢
    • 2021-07-31
    • 1970-01-01
    • 1970-01-01
    • 2019-02-02
    • 1970-01-01
    • 1970-01-01
    • 2017-08-06
    • 2021-11-08
    • 2019-07-18
    相关资源
    最近更新 更多