Why is the vue <template> invalid with v-bind:src?

让人想犯罪 __ 提交于 2021-02-08 10:00:13

问题


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>

Ok,effective

<template :src="getDOM(true)"></template>

getDOM(a){
        if(a){
            return './app.html'
        } else {
            return './app2.html'
        }
}

Not active.

So, what can I do to achieve this effect?


回答1:


It seems like you need to use Vue dynamic components https://vuejs.org/v2/guide/components.html#Dynamic-Components

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.



来源:https://stackoverflow.com/questions/58386043/why-is-the-vue-template-invalid-with-v-bindsrc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!