v-html vue js code example
Example 1: v-html vue js
// js code
const appFunction = Vue.createApp({
data(){
return{
globalFun1:'hello fun 1',
globalFun2:'hello fun 2
',
textFun:''
}
}
,
methods:{
randFun(){
const rand = Math.random();
if (rand <= 0.5){
alert(this.globalFun1)
}else{
alert(this.globalFun2);
}
}
}
})
appFunction.mount('#testfunction');
//html code
Example 2: vue does v-html inject html
return 'Hello World! My name is
!';
Usage will be:
When rendered, the above will be identical to doing this:
Hello World! My name is !