js 调用字符串类型的 js语句
data(){
return{
codeTxt:'(function() {console.log("run")})()'
}
}
<textarea v-model="codeTxt"></textarea>
<button class="btn" @click="runCode">运行</button>
runCode(){
// 第一种
let func = new Function(this.codeTxt);
func();
// 第二种
eval(this.codeTxt)
// 第三种
setTimeout(this.codeTxt)
//第四种
<script>this.codeTxt</script>
}

浙公网安备 33010602011771号