<template> <div class="box"> {{mData.name}} </div> </template> <script setup> import { ref} from 'vue' // 导入 import userMix from "@/common/mixins/user"; // 拿到数据 const { mData } = userMix(); console.log(mData) </script> <style lang="scss" scoped> </style>
user.js代码
import { ref, watch, onMounted } from 'vue' export default function (userData) { const mData = ref(null) onMounted(() => { getData() }) watch(() => data, (newVal, oldVal) => { console.log('watch', newVal, oldVal) }, { deep: true }) const getData = () => { if (!userData) { mData.value = { name: 'lily', age: 10 } } else { mData.value = userData.value } } // 暴露出去 return { mData, getData } }
https://blog.csdn.net/bingjilingvsh2o/article/details/135925874
标签:mData,userData,const,watch,mixin,vue3,import,getData,方法 From: https://www.cnblogs.com/xqschool/p/18312829