SoFunction
Updated on 2025-04-06

Implement the method of dynamically adding li to click the button

As shown below:

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

The above article is the method to dynamically add li to click the button. I hope you can give you a reference and I hope you can support me more.