下面的本机脚本-vue代码我正在解析一个json文件并试图打印它,但由于某些原因我不能在标签中打印json.city.value,但我可以在脚本部分打印它,在readFromJson方法console.log(json.city.value)中工作,在标签标签中我也可以打印parsedJson.city,但parsedJson.city.value不是本机脚本或vuejs的关键字或保留变量吗?下面你可以找到我正在尝试做的事情的简化代码。
<template>
<Page>
<ActionBar title="Welcome to NativeScript-Vue!"/>
<GridLayout columns="*" rows="*">
<Label class="message" :text="parsedJson.city.value" col="0" row="0"/>
</GridLayout>
</Page>
</template>
<script >
let json2 = '{"approved":{"type":"Boolean","value":true,"valueInfo":{}},"city":{"type":"String","value":"Konstanz","valueInfo":{}},"street":{"type":"String","value":"Reichenaustraße 11","valueInfo":{}},"contractNumber":{"type":"String","value":"3847384contractNumber","valueInfo":{}},"description":{"type":"String","value":"","valueInfo":{}}}'
export default {
data() {
return {
msg: 'Hello World!',
parsedJson: {}
}
},
mounted() {
console.log("mounted is worked")
console.log("json to parse is: " + json2)
this.readFromJson(json2)
},
methods: {
readFromJson(input) {
console.log("inside readfromjson")
var json = JSON.parse(input)
console.log("parsed city.value is: " + json.city.value)
this.parsedJson = json
}
}
}
</script>
<style scoped>
ActionBar {
background-color: #53ba82;
color: #ffffff;
}
.message {
vertical-align: center;
text-align: center;
font-size: 20;
color: #333333;
}
</style>发布于 2019-11-14 02:07:03
如果我不得不猜测,它会立即尝试使用一个未定义的值。parsedJson被定义为{},直到后来才被初始化。也许可以尝试将其初始化为空字符串:
parsedJson: {
city: {
value:''
}
}https://stackoverflow.com/questions/58842629
复制相似问题