vue列表排序实现中的this问题
Posted itgezhu
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vue列表排序实现中的this问题相关的知识,希望对你有一定的参考价值。
最近在看vue框架的知识,然后其中有个例子中的this
的写法让我很疑惑
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Page Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div id="demo">
search: <input type="text" v-model="searchName">
<ul>
<li v-for="(p,index) in filterPersons" :key="index">
{{index}} --- {{p.name}} --- {{p.age}}
</li>
</ul>
<button @click="setOrderType(1)">年龄升序</button>
<button @click="setOrderType(2)">年龄降序</button>
<button @click="setOrderType(0)">原本顺序</button>
</div>
<script src="../js/vue.js"></script>
<script>
var vm = new Vue({
el: ‘#demo‘,
data: {
searchName: ‘‘,
/**
* 排序种类:
* 0 - 原本顺序
* 1 - 年龄升序
* 2 - 年龄降序
*/
orderType: 0,
persons: [{
name: ‘Tom‘,
age: 18
},
{
name: ‘Jack‘,
age: 20
},
{
name: ‘Bob‘,
age: 16
},
{
name: ‘Kaka‘,
age: 25
},
{
name: ‘22‘,
age: 23
},
{
name: ‘33‘,
age: 18
},
{
name: ‘Shadow‘,
age: 21
},
{
name: ‘Good‘,
age: 18
},
{
name: ‘Lily‘,
age