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報(bào)錯(cuò)Not?allowed?to?load?local?resource的解決辦法
這篇文章主要給大家介紹了關(guān)于vue報(bào)錯(cuò)Not?allowed?to?load?local?resource的解決辦法,這個(gè)錯(cuò)誤是因?yàn)閂ue不能加載本地資源的原因,需要的朋友可以參考下2023-07-07
Vue3使用Swiper實(shí)現(xiàn)輪播圖示例詳解
這篇文章主要為大家介紹了Vue3使用Swiper實(shí)現(xiàn)輪播圖示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-02-02
Vue.js實(shí)現(xiàn)對(duì)視頻預(yù)覽的示例代碼
本文主要介紹了Vue.js實(shí)現(xiàn)對(duì)視頻預(yù)覽的示例代碼,通過監(jiān)聽文件選擇事件和使用FileReader API,可以實(shí)現(xiàn)視頻文件的預(yù)覽功能,感興趣的可以了解一下2025-01-01
vue3.0父子傳參,子修改父數(shù)據(jù)的實(shí)現(xiàn)
這篇文章主要介紹了vue3.0父子傳參,子修改父數(shù)據(jù)的實(shí)現(xiàn)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-04-04
Vue使用json-server進(jìn)行后端數(shù)據(jù)模擬功能
這篇文章主要介紹了Vue使用json-server進(jìn)行后端數(shù)據(jù)模擬功能,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2018-04-04
前端使用print.js實(shí)現(xiàn)打印功能(基于vue)
最近新接了一個(gè)需求,想要在前端實(shí)現(xiàn)打印功能,下面這篇文章主要給大家介紹了關(guān)于前端使用print.js實(shí)現(xiàn)打印功能(基于vue)的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-05-05

