<template> <div class="home"> <div>调用外部js:{{addNum}}</div> <button @click="clickAdd">加</button> <div>改变外部js参数:{{count}}</div> <button @click="clickChange">修改</button> </div> </template> <script lang="ts" setup> import { reactive, ref } from 'vue'; import { add, accept } from './child' const addNum = ref(add()) const count = ref(accept(12)) const clickAdd = () => { addNum.value = add() } const clickChange = () => { count.value = accept(Math.floor(Math.random() * 10 + 1)) } </script>
import { reactive, ref } from 'vue'; const count = ref(0); const addNum = ref(0); const accept = (data: any) => { return (count.value = data); }; const add = () => { return addNum.value++; }; export { add, accept };
标签:count,const,外部,ts,accept,addNum,add,引入,ref From: https://www.cnblogs.com/1607470370-li/p/17605764.html