我正在尝试在我的公司使用 Vue。目前我们没有使用任何像 Webpack 这样的 Javascript 构建工具。这意味着没有 Babel,(Babel-Standalone 也不是一个选项)。No Babel 意味着没有 Template Literals (``),这使得在纯 Javascript 文件中定义组件变得很痛苦(Internet Explorer 不支持 Template Literals,并且要在干净的多行代码中在 Javascript 中定义模板,您需要 Template Literals,我们需要 IE支持)。我的团队已经同意在不久的将来转向 Laravel 和 Vue,但我们正在通过服务器迁移和代码更新,然后才能正确使用 Vue。
所以我想我会尽量模仿 .vue 布局。首先,我在 PHP 或 HTML 文件中创建组件,在 X-Template 中定义模板以及 Vue 组件实例化和样式。在我的 PHP 控制器/类/等中。我需要该文件,它在 DOM 中呈现。这个解决方案有效,但我有几个问题。
有没有什么不可预见的问题?
有没有办法将这些 .php/HTML 文件的内容作为源包含而不是在 DOM 中呈现?
// MyComponent.php or MyComponent.html
<script type="text/x-template" id="my-component-template">
// component template definition
</script>
<script>
Vue.component('myComponent', {
template: '#my-component-template',
// component vue data/methods/etc
});
</script>
<style>
// component styling
</style>
-
// MyPhpClass.php
public function includeComponents() {
include('path/to/MyComponent.php');
}
吃鸡游戏
隔江千里