<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>vue</title>
<style>
.active {
color:red
}
</style>
</head>
<body>
<div id="app">
<div v-for="(item, key, index) of obj">
{{item}} === {{key}} === {{index}}
</div>
</div>
<!-- 开发环境版本,包含了用帮助的命令行警activeOne告 -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
var app = new Vue({
el: '#app',
data: {
obj: {
firstName: 'tom',
lastName: 'wang',
age: 77,
abc: 'bye bye'
}
}
})
</script>
</body>
</html>
Vue.set(app.obj, 'address' ,'beijing')
app.$set(app.obj, 'home', 'shanghai')
set方法可在对象中新添加键值对
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>vue</title>
<style>
.active {
color:red
}
</style>
</head>
<body>
<div id="app">
<div v-for="item of arr">
{{item}}
</div>
</div>
<!-- 开发环境版本,包含了用帮助的命令行警activeOne告 -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
var app = new Vue({
el: '#app',
data: {
arr: [1,2,3,4,5]
}
})
</script>
</body>
</html>