vue3 ref store 使用数据需要获取value
1,如果定义 let data=ref(‘’)
console.log(data.value)
2, vuex中的数据最好获取且
setup(props, ctx) {
let store = useStore();
let list = computed(() => {
return store.state.list;
});
let add = (val) => {
let flag = true;
list.value.map((item) => { //注意这里就是从vuex里拿来的数据也是需要.value获取内容
if (item.title === val) {
flag = false;
alert("任务已存在");
}
});
if (flag) {
store.commit("addTodo", {
title: val,
complete: false,
});
}
};
let del = (index) => {
store.commit("delTodo", index);
};
return {
list,
add,
del,
};
},
vue3 main.js
import { createApp } from 'vue'
import './style.css'
import 'element-plus/dist/index.css'
import App from './App.vue'
import router from './router'
import store from './store'
import request from './utils/request'
import storage from './utils/storage'
import ElementPlus from 'element-plus'
import api from './api'
const app = createApp(App)
app.config.globalProperties.$request = request
app.config.globalProperties.$storage = storage
app.config.globalProperties.$api = api //请求接口挂载到全局
app.use(store).use(router).use(ElementPlus).mount('#app')
语法糖setup写法
import { reactive, ref, getCurrentInstance } from "vue";
import type { FormInstance, FormRules } from "element-plus";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
const { proxy, ctx } = getCurrentInstance(); //获取全局挂载的自定义变量
const router = useRouter();
const store = useStore();
版权声明:本文由Web学习之路发布,如需转载请注明出处。