there are now three files
data.js
import {calNum} from". / Cal" export const a = {name:calNum}
Cal.vue
< script >
const calNum=0
export default {
calNum }
< / script >
test.vue
< template >
<div style="margin-top: 100px"> <button @click="clickBtn">test</button> </div> </template>
< script >
import {a} from "./data" import cal from "./Cal"
export default {
name: "test", methods:{ clickBtn(){ cal.calNumPP console.log(cal.calNum) console.log(a.name) } } } </script>
< style scoped >
< / style >
I saved a value in cal and referenced it in data. I set a button in the test interface. Every time I click on the value in cal, the value + 1.
now the test finds out why the value in the output cal can be added by one every time I click, but the value in data is always the initial value.