javascript - VueJS 如何使用 x-templates 创建功能组件?
问题描述
我想创建一个带有模板作为单文件组件的 vueJS 功能组件。我正在使用 x 模板,因此我的组件将位于 .html 文件中。
例如,如何将下面的组件变成功能组件?
<!-- my_component.html -->
<script type="text/x-template" id="my-component-template">
<div>
blah blah blah
</div>
</script>
<script>
Vue.component('my-component', {
delimiters: ['[[', ']]'],
template: '#my-component-template',
props: {},
})
</script>
如果我使用 .vue 文件,我只能找到如何执行此操作的示例,在这种情况下您将使用<template functional>
. 你如何对 x-templates 做同样的事情?
解决方案
从文档:
Vue.component('my-component', {
functional: true,
})
推荐阅读
- python - 如何使用 MVC 架构实现 tkinter 应用程序?
- julia - 稀疏矩阵对角化的快速方法(julia):为什么 arpack 这么慢?
- c++ - 修改tasks.json编译多个c++文件
- reactjs - componentDidMount 和 componentWillUnmount 是如何工作的?
- java - 如何将不同驱动器中的 jar 包含到 jar 文件中的清单文件中
- javascript - 基本 js 对象数组引用
- flutter - 我在 HomePage 类中调用 FirstPage 但它没有显示任何内容?
- sql - 使用没有命名目录的 dbms_xmldom.writetofile
- python - 3 Python 3 中的求和问题,Leetcode 中超过了时间限制
- c# - string.IsNullOrEmpty() 不是扩展方法有什么特别的原因吗?