您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

Vue.js2.0中的变化分享

2024/12/19 21:11:44发布17次查看
最近自己在学习vue.js,在看一些课程的时候可能vue更新太块了导致课程所讲知识和现在vue的版本不符,从而报错,本文主要和大家分享vue.js2.0中的变化小结,希望能帮助到大家。
1.关于vue中$index获取索引值已经取消,多用于多个元素的操作,像ul中的li,通过v-for来建立多个li,如果对于其中的某个或者一些li操作的话,需要使用到索引值,用法如下;
<template> <p 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> </p> </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.js 2.5新特性介绍
vue.js做出图书管理平台的详细步骤
vue.js的语法及常用指令的详解
以上就是vue.js2.0中的变化分享的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product