[英]Laravel 5 : How to get the value in data attribute using vue js
我是 vue js 的新手。 在我们的应用程序中,我们验证该值是否已存在于数据库中。 我想通过使其成为动态来改进它。 因此,每当用户键入任何内容时,我都会将数据属性添加到我的字段中。 我在 mthe data 属性中的值是我将检查该值是否已经存在的表。
添加.vue
<label>Code <span class="required-field">*</span></label>
<input type="text" name="code" @keyup="checkCOACode" v-model="coa_code" class="form-control" :data-table="chart_of_accounts">
在我的方法中添加.vue
checkCOACode(e) {
e.preventDefault();
var code = this.coa_code;
var x = event.target.getAttribute('data-table');
alert(x);
return false;
axios.post("/checkIfCodeExists", {code:code})
.then((response) => {
var code_checker = '';
if (response.data == 0) {
$('.add-chart-of-account').removeAttr('disabled','disabled');
}else{
$('.add-chart-of-account').attr('disabled','disabled');
code_checker = 'Code is already exist';
}
this.coa_checker_result = code_checker;
});
},
我在 x 中的值是 null。
问题:如何获取数据属性的值?
您可以通过将ref
属性添加到文本元素来获取vue
中data
属性的值
<input type="text" ref="coaCode" name="code" @keyup="checkCOACode" v-model="coa_code" class="form-control" :data-table="chart_of_accounts">
然后得到那个属性
checkCOACode(e) {
e.preventDefault();
const coa = this.$refs.coaCode
const coaCode = coa.dataset.table
alert(coaCode);
return false;
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.