【问题标题】:NuxtJs get value from input changed by jqueryNuxtJs 从 jquery 更改的输入中获取值
【发布时间】:2020-02-05 11:56:41
【问题描述】:

我有一个隐藏在 nuxtjs 中的输入,并在从 url 获取查询后由 jquery 更新值,我用 jq 编写了这部分,但看起来 nuxtjs 没有读取并获取 jquery 设置的值,它在提交后已经返回 null ,但我想获得 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();

输出:

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

愿望输出:

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

【问题讨论】:

    标签: javascript jquery vue.js nuxt.js


    【解决方案1】:

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

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

    【讨论】:

    • 你读过问题吗?我提到过,我是通过jquery根据url查询字符串来设置值的!
    • 然后呢?这仍然有效,您只需要从 this.$route.query 获取初始参数。添加 jquery 是一种使项目不可维护的方法,应该在 99.9% 的 nuxt 项目中完成
    猜你喜欢
    • 1970-01-01
    • 2021-11-22
    • 1970-01-01
    • 1970-01-01
    • 2018-05-25
    • 1970-01-01
    • 1970-01-01
    • 2016-05-28
    • 1970-01-01
    相关资源
    最近更新 更多