<template>
<div class="index">
<ElSwitch v-model="isActive" active-color="#13ce66" inactive-color="#ff4949">
switch
</ElSwitch>
<div v-for="item in fruitList" :key="item.id">{{ item.name }}</div>
</div>
</template>
<script lang="ts">
import { defineComponent, reactive, toRefs, onMounted } from 'vue';
import { ElSwitch } from 'element-plus';
import 'element-plus/theme-chalk/el-switch.css';
import { useMarket } from '@/store/market';
export default defineComponent({
name: 'Index',
components: {
ElSwitch
},
setup () {
const state: any = reactive({
fruitList: []
});
const isActive = ref(false);
// const marketStore = useMarket();
// await marketStore.getList();
// const { fruitList } = marketStore;
// state.fruitList = fruitList;
const getData = async () => {
const marketStore = useMarket();
await marketStore.getList();
const { fruitList } = marketStore;
state.fruitList = fruitList;
};
onMounted(() => {
getData(); // not ssr
});
return {
...toRefs(state),
isActive
};
}
});
</script>
<style scoped>
</style>
remove getData methods is ok.