首页 > 解决方案 > 如何在Vue中为父组件的数据设置新值

问题描述

<template>
<div>
    <input @keypress.enter="setLocation" class="search" type="text" placeholder="find a city" v-model="newCity">
</div>

<script>
export default {
    props:['city'],
    data(){
        return{
            newCity:""
        }
    },
    methods:{
        setLocation(event){
            this.city = newCity
            this.$emit('newLocation', this.city)
        }
    }
}

当我试图提交它时,它说 newCity 没有定义。他们是否在 Vue.js 更新中更改了 v-model 属性?

标签: javascriptvue.js

解决方案


推荐阅读