大佬救命!TypeScript如何改写vue2.x的watch?

我在vue2.x这样写的watch

watch: {
    service() {
      this.search();
    },
    expandRowKeys: {
      handler(val) {
        this.rowKeys = val;
      },
    },
    datas: {
      handler() {
        this.pagination.limit = 10;
        this.pagination.current = 1;
        this.getTableDatas();
      },
      deep: true,
    },
  },

如果用typescript + vue3怎么写watch,求大佬指教

阅读 1.5k
1 个回答
<script setup>
import { watch, ref, reactive } from 'vue'
const service = ref<string>('')
const datas = reactive<{ a: string }>({ a: '' })
const search = () => {}
watch(
    () => service.value,
    () => search()
)
watch(
    () => datas,
    () => {
        xxxx
    },
    { deep: true }
)
</script>
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题