这是我的代码:
<template>
<div>
<div v-html="data"></div> <button v-on:click="replace">Click Me to replace div contents</button>
</div>
</template>
<script>
export default {
data() {
return {
data: "I will be replaced once you click on button"
}
},
methods: {
clickMe() {
alert("worked");
},
replace(){
this.data = "Why does click me not work? It is loaded from server via ajax <a href v-on:click.prevent='clickMe'>Click Me</a>";
}
}
};
</script>
这里,如果我点击Click Me to replace div contents
,内容将被替换,但事件处理程序clickMe不会触发.这些数据将来自服务器,我需要编译这个字符串,并从Vue的上下文中使用它,以便Vue可以处理事件等.
如何从服务器上下载动态字符串?我正在使用Vue 2.