隐藏图标
点击按钮,图标出现,再点击隐藏。
<div id="app">
<input type="button" value="隐藏图标" @click="change">
<img v-show="isshow" src="imge/3.jpg" alt="">
</div>
<!-- 开发环境版本,包含了有帮助的命令行警告 -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
var app=new Vue({
el:"#app",
data:{
isshow:false
},
methods:{
change:function(){
this.isshow=!this.isshow;
}
}
})
</script>
注意:只有函数里可以用等号。
v-show和v-if的区别。
img v-bind:src="imgSrc"
img :src="imgSrc"
在俩个链接后,来回切换图片,第一张时,左面三角消失,最后一张,右面三角消失。
<body>
<div id="mask">
<div class="center">
<h2 class="title">
<img src="./images/logo.png" alt="">
深圳创维校区环境
</h2>
<!-- 图片 -->
<img :src="imgArr[index]" alt="" />
<!-- 左箭头 -->
<!-- <a href="javascript:void(0)" v-show="index!=0" @click="prev" class="left">
<img src="./images/prev.png" alt="" />
</a> -->
<a href="javascript:void(0)" v-if="index!=0" @click="prev" class="left">
<img src="./images/prev.png" alt="" />
</a>
<!-- 右箭头 -->
<a href="javascript:void(0)" v-show="index @click="next" class="right">
<img src="./images/next.png" alt="" />
</a>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
var app = new Vue({
el: "#mask",
data: {
imgArr: [
"./images/00.jpg",
"./images/01.jpg",
"./images/02.jpg",
"./images/03.jpg",
"./images/04.jpg",
"./images/05.jpg",
"./images/06.jpg",
"./images/07.jpg",
"./images/08.jpg",
"./images/09.jpg",
"./images/10.jpg",
],
index: 0
},
methods: {
prev:function(){
this.index--;
},
next:function(){
this.index++;
}
},
})
</script>
</body>
a href="javascript:void(0)"//表示点击链接后,什么都不发生
<body>
<div id="app">
<input type="button" value="添加数据" @click="add">
<input type="button" value="移除数据" @click="remove">
<li v-for="(it,index) in arr">
{
{
index}}lkq:{
{
it}}
</li>
<h2 v-for="it in shucai" v-bind-title="it.name">
{
{
it.name}}
</h2>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
var app = new Vue({
el: "#app",
data: {
arr:["北京","上海","广州"],
shucai:[
{
name:"蛋炒饭"},
{
name:"烤肉"}
]
},
methods: {
add:function(){
this.shucai.push({
name:"烤冷面"});
},
remove:function(){
//从头开始移除
this.shucai.shift();
}
},
})
</script>
</body>
v-model
获取和设置表单元素的值(双向数据捆绑),表单输入变化后message变化
<body>
<div id="app">
<!-- 按回车之后反应 -->
<input type="text" v-model="message" @keyup.enter="getM">
<h2>{
{
message}}</h2>
</h2>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
var app = new Vue({
el: "#app",
data: {
message:"lkq"
},
methods:{
getM:function(){
alert(this.message);
}
}
})
</script>
</body>
<input v-model="inputValue" @keyup.enter="add" autofocus="autofocus"/>
//===============================
add:function(){
this.list.push(this.inputValue);
},
<button class="destroy" @click="remove(index)"></button>
//====================
remove: function (index) {
this.list.splice(index, 1);
},
<strong>{
{
list.length }}</strong>
<button v-show="list.length!=0" class="clear-completed" @click="clear">
//============================
clear: function () {
this.list = [];
}
v-if="list.length!=0"
和v-show="list.length!=0"
等于0时,隐藏button和span <span class="todo-count" v-if="list.length!=0">
<strong>{
{
list.length }}</strong> items left
</span>
<button v-show="list.length!=0" class="clear-completed" @click="clear">