
<div><input v-model="prefix" placeholder="Filter Surname">div>
<select size="6" v-model="selected">
<option v-for="name in filteredNames" :key="name">{{ name }}option>
<label>Surname: <input v-model="last">label>
<label>Name: <input v-model="first">label>
<button @click="create">Createbutton>
<button @click="update">Updatebutton>
<button @click="del">Deletebutton>
<button @click="reset">Resetbutton>
<p v-if="isShowMessage">{{message}}p>
const initialNames = () => ['于, 于禁', '许, 许褚', '张, 张郃']
createMessage: '创建前请输入内容',
updateMessage: '请选择要修改的名称',
return this.names.filter((n) =>
n.toLowerCase().startsWith(this.prefix.toLowerCase())
;[this.last, this.first] = name.split(', ')
this.isShowMessage = false
if (this.hasValidInput()) {
const fullName = `${this.last}, ${this.first}`
if (!this.names.includes(fullName)) {
this.names.push(fullName)
this.first = this.last = ''
this.isShowMessage = false
this.message = this.repeatMessage
this.isShowMessage = true
this.message = this.createMessage
this.isShowMessage = true
if (this.hasValidInput() && this.selected) {
const i = this.names.indexOf(this.selected)
const fullName = `${this.last}, ${this.first}`
if (!this.names.includes(fullName)) {
this.names[i] = this.selected = `${this.last}, ${this.first}`
this.isShowMessage = false
this.message = this.repeatMessage
this.isShowMessage = true
this.message = this.updateMessage
this.isShowMessage = true
if(this.names.length <=1){
const i = this.names.indexOf(this.selected)
this.selected = this.first = this.last = ''
this.isShowMessage = false
this.message = this.delMessage
this.isShowMessage = true
this.names = initialNames()
return this.first.trim() && this.last.trim()
