欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Vue.js2.0中的变化小结

程序员文章站 2022-07-06 20:31:24
最近自己在学习vue.js,在看一些课程的时候可能vue更新太块了导致课程所讲知识和现在vue的版本不符,从而报错,我会在以后的帖子持续更新vue的变化与更新,大家也可以一...

最近自己在学习vue.js,在看一些课程的时候可能vue更新太块了导致课程所讲知识和现在vue的版本不符,从而报错,我会在以后的帖子持续更新vue的变化与更新,大家也可以一起交流,共同监督学习!

1.关于vue中$index获取索引值已经取消,多用于多个元素的操作,像ul中的li,通过v-for来建立多个li,如果对于其中的某个或者一些li操作的话,需要使用到索引值,用法如下;

<template>
 <div class="hello">
  <h1>{{ msg }}</h1>
  <button v-on:click="reverse">点击</button>
  <input v-model="newtodo" v-on:keyup.enter="add">
  <ul>
   <li v-for="(todo,index) in todos">
    <span>{{todo.text}}</span>
    <button v-on:click="remove(index)">删除</button>
   </li>
  </ul>
 </div>
</template>
<script>
export default {
 name: 'helloworld',
 data () {
  return {
   msg: 'welcome to your vue.js app',
   todos: [
    {text:'我是一开始就有的哦!'}
   ],
   newtodo: ''
  }
 },
 methods: {
  reverse: function(){
   this.msg = this.msg.split('').reverse().join('')
  },
  add: function(){
   var text = this.newtodo.trim();
   if(text){
    this.todos.push({text:text});
    this.newtodo = ''
   }
  },
  remove: function(index){
   this.todos.splice(index,1)
  }
 }
}
</script>

这是我自己组建的一个片段,重点在于index的使用。

总结

以上所述是小编给大家介绍的vue.js2.0中的变化,希望对大家有所帮助