如何使用Vue 2基于道具创建动态标签

vue.js Vue.js

凯阿飞卡卡西

2020-03-12

如何制作类似于vue-router的组件,router-link在其中我可以通过props获得标签以渲染模板?

<my-component tag="ul">
</my-component>

将呈现:

<ul>
  anything inside my-component
</ul>

第1050篇《如何使用Vue 2基于道具创建动态标签》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

1个回答
凯理查德 2020.03.12

您可以使用内置component元素,如下所示:

<component is="ul" class="foo" style="color:red">
  anything inside component
</component>

请参阅:https//vuejs.org/v2/guide/components.html#Dynamic-Components

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android