<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="app">
<div class="bg">
<ul>
<li v-for="(item, index) in arr"
:key="index"
:class="{active: index === current}"
@click="checkNum(index);"
style="height: 32px;border-bottom: 1px solid #dedede;line-height: 32px">
{{item}}
</li>
</ul>
<button title="button" @click="add();">动态添加操作</button>
<ul>
<li v-for="(item, index) in otherArr" :key="index">{{item}}</li>
</ul>
</div>
<div v-html="template">
<div>成都今天的天气是19度,2019-06-15</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script>
new Vue({
el: '#app',
data() {
return {
arr:[1,2,3,4,5,6,7,8,9],
current: '',
msg: "勇士西部总冠军",
count: 0,
template: `<div>成都今天的天气是19度,2019-05-30</div>`,
otherArr: [],
}
},
methods: {
checkNum(index) {
console.log(index);
this.current = index;
},
add() {
if(this.current === ''){
return
}
this.otherArr.push(this.arr[this.current]);
}
}
})
</script>
<style scoped>
li.active{
background: aquamarine;
}
</style>
</body>
</html>
11
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="app">
<div class="bg">
<ul>
<li v-for="(item, index) in arr"
:key="index"
:class="{active: index === current}"
@click="checkNum(index);"
style="height: 32px;border-bottom: 1px solid #dedede;line-height: 32px">
{{item}}
</li>
</ul>
<button title="button" @click="add();">动态添加操作</button>
<ul>
<li v-for="(item, index) in otherArr" :key="index">{{item}}</li>
</ul>
</div>
<div v-html="template">
<div>成都今天的天气是19度,2019-06-15</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script>
new Vue({
el: '#app',
data() {
return {
arr:[1,2,3,4,5,6,7,8,9],
current: '',
msg: "勇士西部总冠军",
count: 0,
template: <div>成都今天的天气是19度,2019-05-30</div>,
otherArr: [],
}
},
methods: {
checkNum(index) {
console.log(index);
this.current = index;
},
add() {
if(this.current === ''){
return
}
this.otherArr.push(this.arr[this.current]);
}
}
})
</script>
<style scoped>
li.active{
background: aquamarine;
}
</style>
</body>
</html><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="app">
<div class="bg">
<ul>
<li v-for="(item, index) in arr"
:key="index"
:class="{active: index === current}"
@click="checkNum(index);"
style="height: 32px;border-bottom: 1px solid #dedede;line-height: 32px">
{{item}}
</li>
</ul>
<button title="button" @click="add();">动态添加操作</button>
<ul>
<li v-for="(item, index) in otherArr" :key="index">{{item}}</li>
</ul>
</div>
<div v-html="template">
<div>成都今天的天气是19度,2019-06-15</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script>
new Vue({
el: '#app',
data() {
return {
arr:[1,2,3,4,5,6,7,8,9],
current: '',
msg: "勇士西部总冠军",
count: 0,
template: <div>成都今天的天气是19度,2019-05-30</div>,
otherArr: [],
}
},
methods: {
checkNum(index) {
console.log(index);
this.current = index;
},
add() {
if(this.current === ''){
return
}
this.otherArr.push(this.arr[this.current]);
}
}
})
</script>
<style scoped>
li.active{
background: aquamarine;
}
</style>
</body>
</html>