vue快捷鍵與基礎(chǔ)指令詳解
v-bind可以簡寫成 :
<img src="{{url}}">→<img :src="url" :width="50px">
v-on:click可以寫成@click
<button @click="up()"></button>
v-if實(shí)例 可以通過對(duì)對(duì)象操作條件來實(shí)現(xiàn)想要展示的效果
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="js/vue.min.js"></script>
</head>
<body>
<div id="app">
<p v-if="seen">現(xiàn)在你看到我了</p>
<template v-if="ok">
<h1>天氣炎熱</h1>
</template>
</div>
<script>
new Vue({
el: "#app",
data: {
seen:false,
ok: true
}
})
</script>
</body>
</html>
v-for實(shí)例:v-for是可以做循環(huán)數(shù)組使用的
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="js/vue.min.js"></script>
</head>
<body>
<div id="app">
<ol>
<li v-for="x in lists">{{x.title}}</li>
</ol>
</div>
<script>
new Vue({
el: "#app",
data: {
lists: [
{ id: 1, title: "臧三" },
{ id: 2, title: '李四' },
{ id: 3, title: "王五" },
]
}
})
</script>
</body>
</html>
v-show實(shí)例:v-show可以操作true/false來實(shí)現(xiàn)效果
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="js/vue.min.js"></script>
</head>
<body>
<div id="app">
<input type="button" value="點(diǎn)擊" v-on:click="a=false" />
<div style="width: 100px;height: 100px;background: red;" v-show="a">
</div>
</div>
<script>
new Vue({
el: "#app",
data: {
a: true
}
})
</script>
</body>
</html>
:class實(shí)例:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="js/vue.js" ></script>
<style>
.red{
color:red
}
.blue{
background: blue;
}
</style>
</head>
<body>
<div id="app">
<p :class="{red:a,blue:b}">我是123</p>
</div>
<script>
new Vue({
el:"#app",
data:{
a:true,
b:true
}
})
</script>
</body>
</html>
第二種方法
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="js/vue.js" ></script>
<style>
.red{
color:red
}
.blue{
background: blue;
}
</style>
</head>
<body>
<div id="app">
<p :class="json">我是123</p>
</div>
<script>
new Vue({
el:"#app",
data:{
json:{
red:true,
blue:true
}
}
})
</script>
</body>
</html>
以上所述是小編給大家介紹的vue快捷鍵與基礎(chǔ)指令詳解,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
詳解Vue webapp項(xiàng)目通過HBulider打包原生APP(vue+webpack+HBulider)
這篇文章主要介紹了詳解Vue webapp項(xiàng)目通過HBulider打包原生APP(vue+webpack+HBulider),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2019-02-02
在vue中動(dòng)態(tài)添加class類進(jìn)行顯示隱藏實(shí)例
今天小編就為大家分享一篇在vue中動(dòng)態(tài)添加class類進(jìn)行顯示隱藏實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-11-11
vue項(xiàng)目如何監(jiān)聽localStorage或sessionStorage的變化
這篇文章主要介紹了vue 項(xiàng)目如何監(jiān)聽localStorage或sessionStorage的變化,幫助大家更好的理解和使用vue框架,感興趣的朋友可以了解下2021-01-01
Vue.js實(shí)現(xiàn)文章評(píng)論和回復(fù)評(píng)論功能
這篇文章主要為大家詳細(xì)介紹了Vue.js實(shí)現(xiàn)文章評(píng)論和回復(fù)評(píng)論功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-04-04

