vue.js - 为什么往这个json里面添加数据失败呢?
本文介绍了vue.js - 为什么往这个json里面添加数据失败呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
提示this.json.push is not a function
<html>
<head>
<style>
</style>
<script type="text/javascript" src="vue.js"></script>
<script type="text/javascript">
window.onload=function(){
new Vue({
el: '#app',
data: {
arr:['1111','2222'],
json:{'b':'bbb','a':'aaa','C':'ccc'}
},
methods:{
add:function(){
this.json.push("'d':'3333'");
}
}
})
}
</script>
</head>
<body>
<div id="app">
<span v-for="(v,k) in json">{{k}}:{{v}}<br /></span>
<button v-on:click="add()">aaaa</button>
</div>
</body>
</html>
解决方案
var json={'a':1};
json['n']=2;
console.log(json)
{a: 1, n: 2}
这篇关于vue.js - 为什么往这个json里面添加数据失败呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文