项目中遇到需要执行后台返回的js字符串函数可以使用eval()方法进行解析运行
<template>
</template>
<script>
export default{
data(){
return{
fun:'(function(){if(_this.planObj.grenn===0){return 10}else{return 11}})()',
obj:{
green:0
}
}
},
created(){
let _this = this
console.log(eval(this.fun)) // 10
}
}
</script>
<style>
</style>