Vue操作实例
参考文章:https://blog.csdn.net/w13966597931/article/details/125867051
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=21.0"> <title>Document</title> <script src="https://cdn.jsdelivr.net/npm/vue@2.5.16/dist/vue.js"></script> </head> <body> <div id="app"> <!-- 普通获取文本 --> <h2>{{msg}}</h2> <h2 v-html="msg"></h2> <!-- 设置元素的innerHTML --> <!-- v-text只能获取该值 --> <h2 v-text="url"></h2> <!-- v-html内联html标签 --> <h2 v-html="url"></h2> <h2 v-text="food"></h2> <input type="button" value="你好1" v-on:click="show1"> <input type="button" value="你好2" v-on:click="show2"> <input type="button" value="今天学习不?" @click="show3"> <input type="button" value="双击事件" @dblclick="show4"> <input type="button" :value="flag_txt" @click="changge"> <img v-show="flag" src="./vue.jpg" width="100px" height="100px"> </div> </body> <script> var obj = new Vue({ el: "#app", data:{ "msg": "java程序员", "food": "宫保鸡丁", "url": "<a href='https://www.baidu.com'>百度一下</a>", "flag":true, "flag_txt":"隐藏", } , methods:{ show1:function(){ alert("你好!"); }, show2:function(){ alert("喜欢你"); }, show3:function(){ alert("今天不学习,明天变垃圾!"); }, show4:function(){ console.log(this.food); this.food += "真好吃"; }, changge:function(){ this.flag = !this.flag; this.flag_txt = this.flag ? "隐藏" : "显示"; } }, }) </script> </html>