I am making my first Vue 2 component (within a Laravel 5.3 app) but run into a instance/scope problem which I have spent hours trying to solve, but just cannot get it to work!
My component generates a list of orders and within each order there is a list of users (advisors). I want to be able to select a user for an order and then assign the user to the order.
The latest version of my component looks like this;
Vue.component('unassigned-orders', {
template: `
<table id="assignOrder" class="table table-hover">
<thead>
// table headers
</thead>
<tr v-for="(unassignedOrder, key) in unassignedOrders"
:key="unassignedOrder.order_id">
<td>{{ unassignedOrder.order_id }}</td>
<td>{{ unassignedOrder.first_name }} {{ unassignedOrder.last_name }}</td>
<td>{{ unassignedOrder.order_status }}</td>
<td><select @change="assignAdvisor()">
<option v-for="advisor in advisors" :value="advisor.id" >
{{ advisor.first_name }} {{ advisor.last_name }}
</option>
</select></td>
<td><a class="btn btn-default">
Set Advisor {{ unassignedOrder.assignTo }}</a></td>
</tr>
</table>`,
data: function() {
return {
unassignedOrders: [{'assignTo' : ''}],
advisors: ''
}
},
methods: {
assignAdvisor: function() {
this.assignTo = event.target.value;
}
},
mounted() {
axios.get('url').then(response => this.advisors = response.data);
axios.get('url').then(response => this.unassignedOrders = response.data);
}
});
I do not get any errors, but the functionality does not work (I just need to update var assignTo to the relevant order, I am sure I'll be able to figure the rest out).
I am sure I am missing something really simple, anyone got any pointers?
Thanks
assignToin the object returned by the component's data method? You can set the value tonullor an empty string.assignTo: '',on its own line within the data function as opposed to nested within unassignedOrders, but it had the same result, i.e. nothing..unassignedOrders. When theselectin an unassigned order emits achangeevent it is supposed to set theassignToproperty of that order. Does that sound right?assignTobutton is clicked I will run an AJAX to update the database (to add the selected user to the order). I just can't get the value intoassignTo...