search

Home  >  Q&A  >  body text

javascript - How to use vue.js to implement deletion and undelete functions?

How to use VUE to implement deletion and undelete functions?

  <p id="one">
     <p>
         <span>1</span>
         <span>这是一条信息</span>
         <span style="color: red">删除</span>

     </p>
     <p>
         <span>2</span>
         <span>这是一条信息</span>
         <span style="color: red">删除</span>

     </p>
 </p>
 <p id="two">
     <p>
         <span>2</span>
         <span>这是一条信息</span>
         <span style="color: green">撤销删除</span>

     </p>
 </p>
 

Finally, by clicking the button, you can get the deleted information and the information that has not been deleted.

phpcn_u1582phpcn_u15822746 days ago777

reply all(2)I'll reply

  • 仅有的幸福

    仅有的幸福2017-05-19 10:14:38

    When generating information, add the ID and use the ID to obtain the corresponding information

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-05-19 10:14:38

    When deleting, push the value to be deleted to an array delList

    When undoing, pop out the last deleted value

    function TM(arr){
        this.arr = arr; 
        this.delArr = [];     
    
        this.remove = (val) => {
            this.arr = this.arr.filter(e => e !== val); 
            this.delArr.push(val); 
        }
    
        this.back = () => {
            var val = this.delArr.pop(); 
            this.arr.push(val); 
            return val; 
        }
    }

    reply
    0
  • Cancelreply