vue.js - 我这个数组写的不对吗?
本文介绍了vue.js - 我这个数组写的不对吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
为什么结果是图片中这样的呢?
<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:['apple','pear','aaa']
}
})
}
</script>
</head>
<body>
<div id="app">
{{arr}}
</div>
</body>
</html>
解决方案
如果只想显示其中一个可以直接{{arr[0]}}
取值
如果想全展示请用v-for
循环
<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:['apple','pear','aaa']
}
})
}
</script>
</head>
<body>
<div id="app">
<p v-for="item in arr">{{item}}</p>
</div>
</body>
</html>
这篇关于vue.js - 我这个数组写的不对吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文