繁体   English   中英

NuxtJs 从由 jquery 更改的输入中获取值

[英]NuxtJs get value from input changed by jquery

I have an input hidden in nuxtjs, and value update by jquery after get query from url, I wrote this part with jq but look like nuxtjs not read and get value that set by jquery, it already return null after submit, but I want to获取 jq 设置的值。 但是,如果我在输入上写它可以正常工作并返回值,但是我想在页面加载时返回值,而不需要用户进行任何按键操作。

NuxtJs:

<input v-model="requestObj.case" name="case" type="text" value="" id="ServiceCase"/>

data() {
    return {
        requestObj: {
            case: null,
        },
    }
}

methods: {
sendMail() { // this call when form submit
console.log(this.requestObj.case) // return null
}
}

jQuery:

我只能通过jq更新value

$('#ServiceCase').val(s).attr('value',s).change();

Output:

<input name="case" type="text" value="Burglary" id="ServiceCase">
console: null

渴望 Output:

<input name="case" type="text" value="Burglary" id="ServiceCase">
console: Burglary

您只需在 model 中设置初始值,而不是在 html 中。 并且不要使用 jquery。 例如


data() {
    return {
        requestObj: {
            case: 'Bulgaria',
        },
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM