【发布时间】:2021-04-23 14:38:38
【问题描述】:
我是Vue 的新手,想将我成功收到的JSON 内容传递给HTML var {{info}},console.log(info) 显示我正确的JSON 内容。如果我使用mounted() 函数,它也会正确显示。
<template>
<DIV>
{{info}}
</DIV>
</template>
<script>
export default defineComponent({
components: {
HelloWorld
},
data() {
return {
}
},
setup() {
const toast = useToast();
const text = ref('');
var info;
//const jsonobj = ref('');
function search() {
toast.add({ severity: 'info', summary: 'fetch data', detail: text });
axios
.get('http://localhost:7071/api/paramval/' + text.value)
.then(response => (info = response))
console.log(info);
}
return {
text,
search,
info
}
},
mounted () {
/*axios
.get('http://localhost:7071/api/paramval/439074042')
.then(response => (this.info = response))*/
}
})
</script>
感谢您的帮助!
【问题讨论】: