通过三个长度都为1000的数组循渲染原生input,自己封装的input,el-input
- 当注释掉el-input后,输入十分流畅
- 不注释掉el-input,输入十分卡顿,看了下vue-devtools,更新input,my-inputh,el-input都会导致所有的el-input同时更新,el-input的数量越多输入卡顿时间就越长
想知道为什么input,my-input,el-input都会引发el-input更新
附上我的测试代码
<template>
<div>
<div style="width: 100%; background-color: #ff0;">
<input type="text" v-for="(item, index) in list1" v-model="item.value" :key="index" />
</div>
<div style="width: 100%; background-color: #f00;">
<MyInput type="text" v-for="(item, index) in list2" v-model="item.value" :key="index + 'my'" />
</div>
<div style="width: 100%; background-color: #00f;">
<el-input type="text" v-for="(item, index) in list3" v-model="item.value" :key="index + 'el'" />
</div>
</div>
</template>
<script>
import MyInput from "./myInput";
const length = 1000;
export default {
name: "test",
components: {
MyInput,
},
data() {
return {
list1: Array(length)
.fill(0)
.map((_) => ({ value: "" })),
list2: Array(length)
.fill(0)
.map((_) => ({ value: "" })),
list3: Array(length)
.fill(0)
.map((_) => ({ value: "" })),
};
},
};
</script>
<style scoped></style>
<template>
<div>
<div>
<div>
<div>
<input type="text" v-model="value" @input="handleInput" />
</div>
</div>
</div>
</div>
</template>
<script>
export default {
name: "MyInput",
props: {
value: {
type: String,
default: "",
},
},
methods: {
handleInput(e) {
this.$emit("input", e.target.value);
},
},
};
</script>
<style scoped></style>
https://github.com/vuejs/vue/issues/11592