首页 > 语言 > JavaScript > 正文

vue.js 实现点击按钮动态添加li的方法

2024-05-06 15:30:28
字体:
来源:转载
供稿:网友

如下所示:

<!DOCTYPE html><html>  <head> <meta charset="UTF-8"> <title></title> <script type="text/javascript" src="js/vue.js" ></script> </head>  <body> <div id="todo-list-example">  <button v-on:click="ss">保存 </button>  <ul>  <li is="todo-item" v-for="(todo, index) in todos" v-text="sv" v-on:click="hh"></li>  </ul> </div> </body> <script> Vue.component('todo-item', {  template: `  <li v-on:click="$emit('click')">  {{ text }}  </li>`,  props: ['text'] }) new Vue({  el: '#todo-list-example',  data: {  todos: [   '+添加'  ],  sv:'+添加'  },  methods: {  ss: function() {   this.todos.push(this.sv)  },  hh:function(){   alert(1)  }  } }) </script> </html>

以上这篇vue.js 实现点击按钮动态添加li的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持错新站长站。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选