引入外部ts文件,修改外部ts参数

发布时间 2023-08-04 14:11:24作者: 欢者自欢
<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 };