为什么 vue <template>v-bind:src 无效? [英] Why is the vue <template> invalid with v-bind:src?
本文介绍了为什么 vue <template>v-bind:src 无效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
想动态切换html内容,所以用vue-loader src导入,但是v-bind:src根本不生效.
I want to dynamically switch html content, so I used vue-loader src to import, but v-bind:src doesn't take effect at all.
<template src="./app.html"></template>
好的,有效
<template :src="getDOM(true)"></template>
getDOM(a){
if(a){
return './app.html'
} else {
return './app2.html'
}
}
未激活.
那么,我该怎么做才能达到这个效果?
So, what can I do to achieve this effect?
推荐答案
看来你需要使用 Vue 动态组件https://vuejs.org/v2/guide/components.html#Dynamic-组件
It seems like you need to use Vue dynamic components https://vuejs.org/v2/guide/components.html#Dynamic-Components
您可以使用您需要的不同模板制作几个组件,只需更改 is
属性即可.不要忘记导入所需的组件并注册它们.
You can make a couple of components with the different templates that you need and just change the is
property. Don't forget to import the needed components and register them.
这篇关于为什么 vue <template>v-bind:src 无效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文