将html结构写在一对script标签中,设置type=“x-template”
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <script src="./vue.js"></script> </head> <body> <div id="demo"> <span>miaov ketang</span> </div> <script type="x-template" id="temp"> <div> hello {{abc}} <span>miaov</span> </div> </script> <script> let obj={ html:"<div>hello,miaov</div>", abc:1 }; var vm=new Vue({ el:"#demo", data:obj, template:"#temp" /*将新渲染的str替换掉前面的整个div*/ // }) </script> </body> </html>
.