admin管理员组文章数量:1023053
I've read several posts where the $refs property of the vue instance is only available in the mounted hook of Vue.js
I have a custom event listener set up in my vue ponent that listens to a change of date in an input field. Once this happens I am changing the query parameter of the date to fetch a new set of results from my API.
My problem is that I cannot run the refresh() method with my new query parameter.
Here's my ponent
<template>
<vuetable
:fields="table.fields"
:apiUrl="table.url"
:append-params="urlParams"
></vuetable>
</template>
<script>
import { eventBus } from '../app.js';
import Vuetable from 'vuetable-2';
import moment from 'moment';
export default {
data: function() {
return {
urlParams: {
d: moment().add(1, 'd')._d, // date selected
//p: null, // product selected
},
lineItems: '',
table: {
url: '/home/bakery/lineitems/', // by default we need tomorrows orders
showTable: false,
fields: [
{ name: 'order_id', title: 'Order#' },
{ name: 'customer_name', title: 'Customer' },
{ name: 'qty', title: 'QTY' },
{ name: 'product_name', title: 'Product' },
{ name: 'variation', title: 'Variations', callback: 'formatArray' },
{ name: 'collection_time', title: 'Timeslot' },
{ name: 'store', title: 'Transport' },
{ name: 'order_id', title: 'Actions' }
],
},
}
},
ponents: {
'vuetable': Vuetable,
},
methods: {
filterByProduct: function(val, ev) {
this.selectedProduct = val;
this.table.url = '/home/bakery/lineitems?d=' + moment(data) + '&p=' + val;
},
formatArray: function(val) {
var valArray = JSON.parse(val); // convert API string to array
var text = '<ul>';
for(var i in valArray) {
text += '<li>' + valArray[i].key + ': ' + valArray[i].value + '</li>';
}
text += '</ul>';
return text;
},
},
mounted: function() {
//console.log(this.$refs);
eventBus.$on('dateSelected', (data) => {
self = this;
self.urlParams.d = moment(data);
Vue.nextTick( function() {
self.$refs.vuetable.refresh();
});
});
eventBus.$on('filter-set', (data) => {
console.log(data);
});
// continuously check for updates in the db
setInterval(function () {
//this.getProductTotals(this.selectedDate);
}.bind(this), 5000);
}
}
</script>
Everything runs 100% fine including running Vue.nextTick()
If I console.log self.$refs I get an empty object. I'm unable to get anything other than an empty Object even in my root app.js file.
I've read several posts where the $refs property of the vue instance is only available in the mounted hook of Vue.js
I have a custom event listener set up in my vue ponent that listens to a change of date in an input field. Once this happens I am changing the query parameter of the date to fetch a new set of results from my API.
My problem is that I cannot run the refresh() method with my new query parameter.
Here's my ponent
<template>
<vuetable
:fields="table.fields"
:apiUrl="table.url"
:append-params="urlParams"
></vuetable>
</template>
<script>
import { eventBus } from '../app.js';
import Vuetable from 'vuetable-2';
import moment from 'moment';
export default {
data: function() {
return {
urlParams: {
d: moment().add(1, 'd')._d, // date selected
//p: null, // product selected
},
lineItems: '',
table: {
url: '/home/bakery/lineitems/', // by default we need tomorrows orders
showTable: false,
fields: [
{ name: 'order_id', title: 'Order#' },
{ name: 'customer_name', title: 'Customer' },
{ name: 'qty', title: 'QTY' },
{ name: 'product_name', title: 'Product' },
{ name: 'variation', title: 'Variations', callback: 'formatArray' },
{ name: 'collection_time', title: 'Timeslot' },
{ name: 'store', title: 'Transport' },
{ name: 'order_id', title: 'Actions' }
],
},
}
},
ponents: {
'vuetable': Vuetable,
},
methods: {
filterByProduct: function(val, ev) {
this.selectedProduct = val;
this.table.url = '/home/bakery/lineitems?d=' + moment(data) + '&p=' + val;
},
formatArray: function(val) {
var valArray = JSON.parse(val); // convert API string to array
var text = '<ul>';
for(var i in valArray) {
text += '<li>' + valArray[i].key + ': ' + valArray[i].value + '</li>';
}
text += '</ul>';
return text;
},
},
mounted: function() {
//console.log(this.$refs);
eventBus.$on('dateSelected', (data) => {
self = this;
self.urlParams.d = moment(data);
Vue.nextTick( function() {
self.$refs.vuetable.refresh();
});
});
eventBus.$on('filter-set', (data) => {
console.log(data);
});
// continuously check for updates in the db
setInterval(function () {
//this.getProductTotals(this.selectedDate);
}.bind(this), 5000);
}
}
</script>
Everything runs 100% fine including running Vue.nextTick()
If I console.log self.$refs I get an empty object. I'm unable to get anything other than an empty Object even in my root app.js file.
Share Improve this question asked Oct 30, 2017 at 12:34 Marcus ChristiansenMarcus Christiansen 3,2179 gold badges53 silver badges93 bronze badges1 Answer
Reset to default 5You are trying to access this.$refs.vuetable
, but you don't have any elements in your template with the ref
attribute.
Add ref="vuetable"
to your <vuetable>
tag:
<template>
<vuetable
:fields="table.fields"
:apiUrl="table.url"
:append-params="urlParams"
ref="vuetable"
></vuetable>
</template>
Here's the documentation on refs
.
I've read several posts where the $refs property of the vue instance is only available in the mounted hook of Vue.js
I have a custom event listener set up in my vue ponent that listens to a change of date in an input field. Once this happens I am changing the query parameter of the date to fetch a new set of results from my API.
My problem is that I cannot run the refresh() method with my new query parameter.
Here's my ponent
<template>
<vuetable
:fields="table.fields"
:apiUrl="table.url"
:append-params="urlParams"
></vuetable>
</template>
<script>
import { eventBus } from '../app.js';
import Vuetable from 'vuetable-2';
import moment from 'moment';
export default {
data: function() {
return {
urlParams: {
d: moment().add(1, 'd')._d, // date selected
//p: null, // product selected
},
lineItems: '',
table: {
url: '/home/bakery/lineitems/', // by default we need tomorrows orders
showTable: false,
fields: [
{ name: 'order_id', title: 'Order#' },
{ name: 'customer_name', title: 'Customer' },
{ name: 'qty', title: 'QTY' },
{ name: 'product_name', title: 'Product' },
{ name: 'variation', title: 'Variations', callback: 'formatArray' },
{ name: 'collection_time', title: 'Timeslot' },
{ name: 'store', title: 'Transport' },
{ name: 'order_id', title: 'Actions' }
],
},
}
},
ponents: {
'vuetable': Vuetable,
},
methods: {
filterByProduct: function(val, ev) {
this.selectedProduct = val;
this.table.url = '/home/bakery/lineitems?d=' + moment(data) + '&p=' + val;
},
formatArray: function(val) {
var valArray = JSON.parse(val); // convert API string to array
var text = '<ul>';
for(var i in valArray) {
text += '<li>' + valArray[i].key + ': ' + valArray[i].value + '</li>';
}
text += '</ul>';
return text;
},
},
mounted: function() {
//console.log(this.$refs);
eventBus.$on('dateSelected', (data) => {
self = this;
self.urlParams.d = moment(data);
Vue.nextTick( function() {
self.$refs.vuetable.refresh();
});
});
eventBus.$on('filter-set', (data) => {
console.log(data);
});
// continuously check for updates in the db
setInterval(function () {
//this.getProductTotals(this.selectedDate);
}.bind(this), 5000);
}
}
</script>
Everything runs 100% fine including running Vue.nextTick()
If I console.log self.$refs I get an empty object. I'm unable to get anything other than an empty Object even in my root app.js file.
I've read several posts where the $refs property of the vue instance is only available in the mounted hook of Vue.js
I have a custom event listener set up in my vue ponent that listens to a change of date in an input field. Once this happens I am changing the query parameter of the date to fetch a new set of results from my API.
My problem is that I cannot run the refresh() method with my new query parameter.
Here's my ponent
<template>
<vuetable
:fields="table.fields"
:apiUrl="table.url"
:append-params="urlParams"
></vuetable>
</template>
<script>
import { eventBus } from '../app.js';
import Vuetable from 'vuetable-2';
import moment from 'moment';
export default {
data: function() {
return {
urlParams: {
d: moment().add(1, 'd')._d, // date selected
//p: null, // product selected
},
lineItems: '',
table: {
url: '/home/bakery/lineitems/', // by default we need tomorrows orders
showTable: false,
fields: [
{ name: 'order_id', title: 'Order#' },
{ name: 'customer_name', title: 'Customer' },
{ name: 'qty', title: 'QTY' },
{ name: 'product_name', title: 'Product' },
{ name: 'variation', title: 'Variations', callback: 'formatArray' },
{ name: 'collection_time', title: 'Timeslot' },
{ name: 'store', title: 'Transport' },
{ name: 'order_id', title: 'Actions' }
],
},
}
},
ponents: {
'vuetable': Vuetable,
},
methods: {
filterByProduct: function(val, ev) {
this.selectedProduct = val;
this.table.url = '/home/bakery/lineitems?d=' + moment(data) + '&p=' + val;
},
formatArray: function(val) {
var valArray = JSON.parse(val); // convert API string to array
var text = '<ul>';
for(var i in valArray) {
text += '<li>' + valArray[i].key + ': ' + valArray[i].value + '</li>';
}
text += '</ul>';
return text;
},
},
mounted: function() {
//console.log(this.$refs);
eventBus.$on('dateSelected', (data) => {
self = this;
self.urlParams.d = moment(data);
Vue.nextTick( function() {
self.$refs.vuetable.refresh();
});
});
eventBus.$on('filter-set', (data) => {
console.log(data);
});
// continuously check for updates in the db
setInterval(function () {
//this.getProductTotals(this.selectedDate);
}.bind(this), 5000);
}
}
</script>
Everything runs 100% fine including running Vue.nextTick()
If I console.log self.$refs I get an empty object. I'm unable to get anything other than an empty Object even in my root app.js file.
Share Improve this question asked Oct 30, 2017 at 12:34 Marcus ChristiansenMarcus Christiansen 3,2179 gold badges53 silver badges93 bronze badges1 Answer
Reset to default 5You are trying to access this.$refs.vuetable
, but you don't have any elements in your template with the ref
attribute.
Add ref="vuetable"
to your <vuetable>
tag:
<template>
<vuetable
:fields="table.fields"
:apiUrl="table.url"
:append-params="urlParams"
ref="vuetable"
></vuetable>
</template>
Here's the documentation on refs
.
本文标签: javascriptVueTable 2 refs object empty in mounted hookStack Overflow
版权声明:本文标题:javascript - VueTable 2 $refs object empty in mounted hook - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745559198a2156058.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论