1个回答

test
2024-07-12
class fun {
constructor() {
this.authMap = {}
// this.initAuth()
}
async initAuth() {
const isshowCreateApp = await getAuthorization()
this.setAuthMap({ createAuth: isshowCreateApp })
}
setAuthMap(authmap) {
this.authMap = {
...authmap
}
console.log(this.authMap, 'this.authMap')
}
}
function getAuthorization() {
return new Promise((res) => {
setTimeout(() => {
res('666')
},)
})
}
async function fn() {
let connector = new fun()
await connector.initAuth()
console.log(connector, "this.connector.authMap")
}
fn()
这样的话不用改你自己的代码
<script>
import fun from './1.js'
export default {
data () {
return {
connector: new fun()
}
},
watch: {
'connector.authMap' (newVal, oldVal) {
console.log(this.connector.authMap);
}
}
}
</script>
回复

适合作为回答的
- 经过验证的有效解决办法
- 自己的经验指引,对解决问题有帮助
- 遵循 Markdown 语法排版,代码语义正确
不该作为回答的
- 询问内容细节或回复楼层
- 与题目无关的内容
- “赞”“顶”“同问”“看手册”“解决了没”等毫无意义的内容