You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.4 KiB
48 lines
1.4 KiB
2 years ago
|
<!DOCTYPE html>
|
||
|
<html lang="en">
|
||
|
<head>
|
||
|
<meta charset="UTF-8">
|
||
|
<title>更新时的一个问题</title>
|
||
|
<script type="text/javascript" src="../vue.js"></script>
|
||
|
</head>
|
||
|
<body>
|
||
|
<div id="root">
|
||
|
<!-- 遍历列表-->
|
||
|
<h2>人员列表</h2>
|
||
|
<button @click="updateMei">更新马冬梅信息</button>
|
||
|
<ul>
|
||
|
<li v-for="(data, index) in listData" :key="data.id">
|
||
|
{{data.name}} - {{data.age}} - {{data.sex}}
|
||
|
</li>
|
||
|
</ul>
|
||
|
</div>
|
||
|
</body>
|
||
|
<script type="text/javascript">
|
||
|
Vue.config.productionTip = false
|
||
|
|
||
|
// 使用computed实现
|
||
|
const vm = new Vue({
|
||
|
el: "#root",
|
||
|
data: {
|
||
|
keyword: '',
|
||
|
sortType: 0, // 0-原顺序 1-年龄降序 2-年龄升序
|
||
|
listData: [
|
||
|
{id: 1, name: '马冬梅', age: 25, sex: '女'},
|
||
|
{id: 2, name: '周冬雨', age: 19, sex: '女'},
|
||
|
{id: 3, name: '周杰伦', age: 20, sex: '男'},
|
||
|
{id: 4, name: '温兆伦', age: 17, sex: '男'}
|
||
|
],
|
||
|
},
|
||
|
methods: {
|
||
|
updateMei() {
|
||
|
// this.listData[0].name = '马老师'
|
||
|
// this.listData[0].age = 55
|
||
|
// this.listData[0].sex = '男'
|
||
|
// this.listData[0] = {id: 1, name: '马老师', age: 55, sex: '男'}
|
||
|
this.listData.splice(0, 1, {id: 1, name: '马老师', age: 55, sex: '男'} )
|
||
|
}
|
||
|
}
|
||
|
})
|
||
|
|
||
|
</script>
|
||
|
</html>
|