Vuejs2 从vuex存储区加载所有计算数据后,如何加载数据?
使用Laravel 5.7/Vuejs 2.6/Vuex 3.1应用程序时,我使用“vue select”:“^2.6.4”,并在打开包含所需现有数据的表单时使用 用变量填充select组件的步骤Vuejs2 从vuex存储区加载所有计算数据后,如何加载数据?,vuejs2,Vuejs2,使用Laravel 5.7/Vuejs 2.6/Vuex 3.1应用程序时,我使用“vue select”:“^2.6.4”,并在打开包含所需现有数据的表单时使用 用变量填充select组件的步骤 selection_status = {key: ‘key’, label: ‘label’} <v-select v-model="selection_status" data-vv-name="userRow.status" :options="cu
selection_status = {key: ‘key’, label: ‘label’}
<v-select
v-model="selection_status"
data-vv-name="userRow.status"
:options="customerStatusValueArray"
v-validate="'required'"
id="status"
name="status"
class="form-control editable_field"
placeholder="Select option"
></v-select>
data() {
return {
...
selection_status: null,
mounted() {
this.loadCustomer();
}, // mounted() {
loadCustomer() {
axios.get(window.API_VERSION_LINK + 'personal/customers/' + this.user_id).then((response) => {
this.userRow = response.data.user;
this.customerStatusValueArray.map((nextCustomerStatusValue, index) => {
if (nextCustomerStatusValue.key == this.userRow.status) {
this.selection_status = {key: this.userRow.status, label: nextCustomerStatusValue.label};
}
});
...
computed: {
customerStatusValueArray() {
return this.$store.getters.customerStatusValueArray;
},
加载vuex存储区中的所有计算数据后
谢谢 您可能应该使用加载状态, 还要考虑使用Cudid()来调用这个.Load Cuffor()。 因为mounted()是在呈现组件后调用的
<v-select v-if="loaded' />
<my-loader v-else/>
data() {
loaded: false,
}
loadCustomer() {
axios.get('url').then((response) => {
this.loaded = true;
});
}
看起来,加载页面后会呈现v-select组件?@PetroGromovo v-select只有在设置“this.loaded=true”时才会呈现。或者,您可以初始化选择状态:[],并添加一些消息,说明其加载不会出现任何错误。这很有趣,但似乎还不够,因为vuex store中的计算值customerStatusValueArray必须在loadCustomer方法中初始化/填充,但看起来它是空的…@PetroGromovo您可以使用customerStatusValueArray,我将更新我的答案
<v-select v-if="loaded' />
<my-loader v-else/>
data() {
loaded: false,
}
loadCustomer() {
axios.get('url').then((response) => {
this.loaded = true;
});
}