vue案列
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> </head> <body> <div id="div2" v-bind:style="mystyle"> <section> <h1>{{title}}</h1> <table> <tr> <th>id</th> <th>姓名</th> <th>性别</th> </tr> <tr v-for="person in persons"> <td>{{person.id}}</td> <td>{{person.name}}</td> <td>{{person.sex}}</td> <td> <a href="#" @click="remove(person.id)">删除</a> </td> </tr> </table> </section> <button @click="changeStyle"> 变色</button> <div><input v-model.number="person.id" ></div> <div><input v-model.number="person.name" ></div> <div><input v-model.number="person.age"></div> <button @click="submit">提交</button> </div> <script src="css/vues.js"></script> <script> var vm=new Vue({ el:"#div2", data:{ title:'渲染数据', persons:[{ name:'张三', sex:'男', id:18 }, { name:'李四', sex:'男', id:22 }, { name:'李四', sex:'男', id:22 }, { name:'王五', sex:'女', id:38 }, ], mystyle:"color:red", person:{id:0,name:"",sex:0} }, methods:{ changeStyle:function(){ var colors=["green","red","yellow"]; var randColor=colors[Math.floor(Math.random()*colors.length)]; this.mystyle="color:"+randColor; }, submit:function(){ this.persons.push({ id:this.person.id, name:this.person.name, sex:this.person.sex, }); console.log(this.persons); }, remove:function(id){ this.persons=this.persons.filter((b) => b.id != id); } }, watch:{ id:function(n,o){ console.log(`修改后n:${n} 修改 o:${o}`) } }, computed:{ revMsg:function(){ return this.msg.split("").reverse().join(""); } } }); </script> </body> </html>
运行效果:
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下