[英]How to pass data within "export default" to outside of export default Vue.js
I got my API data store in carcount
for sure, but I can't use that carcount
in const
outside the export default, any suggestion please?我确实在carcount
获得了我的 API 数据存储,但是我不能在导出默认值之外的const
使用那个carcount
, carcount
什么建议吗?
export default {
data() {
return {
carcount: [],
};
},
Create() {
axios
.get("http://www.mustavi.com/TotalVehicles/?param1=2020-09-04")
.then((res) => {
this.carcount = res.data.data.carCount;
});
},
};
const totalcar = this.carcount
I do it this way be cause I have to export the whole const as below我这样做是因为我必须按如下方式导出整个常量
const locationData = [
{
value: totalcar,
name: 'Car'
}
];
export {
locationData,
};
Vue components are not designed for this. Vue 组件不是为此而设计的。 If you need to pass data to another component use events or vuex for state management.如果您需要将数据传递给另一个组件,请使用事件或 vuex 进行状态管理。
export default {
Create() {
axios
.get("http://www.mustavi.com/TotalVehicles/?param1=2020-09-04")
.then((res) => {
this.$emit('carcount', {
value: res.data.data.carCount,
name: 'Car'
});
});
},
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.