国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

vue基礎之v-bind屬性、class和style用法分析

2019-11-19 12:00:45
字體:
來源:轉載
供稿:網友

本文實例講述了vue基礎之v-bind屬性、class和style用法。分享給大家供大家參考,具體如下:

一、屬性

屬性:

v-bind:src=""
width/height/title....

簡寫:

:src=""    推薦

<img src="{{url}}" alt="">    效果能出來,但是會報一個404錯誤
<img v-bind:src="url" alt="">    效果可以出來,不會發404請求

window.onload=function(){      new Vue({        el:'#box',        data:{          url:'https://www.baidu.com/img/bd_logo1.png',          w:'200px',          t:'這是一張美麗的圖片'        },        methods:{        }      });    };
<div id="box">    <!--<img src="{{url}}" alt="">-->    <img :src="url" alt="" :width="w" :title="t">  </div>

二、class和style

:class=""     v-bind:class=""
:style=""     v-bind:style=""
:class="[red]"     red是數據
:class="[red,b,c,d]"

<!DOCTYPE html><html lang="en"><head>  <meta charset="UTF-8">  <title></title>  <style>    .red{      color: red;    }    .blue{      background: blue;    }  </style>  <script src="vue.js"></script>  <script>    window.onload=function(){      new Vue({        el:'#box',        data:{          claOne:'red',//這里的red是樣式class類名          claTwo:'blue'        },        methods:{        }      });    };  </script></head><body>  <div id="box">    <!--這里的calOne,calTwo指data里的數據-->    <strong :class="[claOne,claTwo]">文字...</strong>  </div></body></html>

:class="{red:true, blue:false}"http://這里是{ json}

<style>    .red{      color: red;    }    .blue{      background: blue;    }  </style>  <script src="vue.js"></script>  <script>    window.onload=function(){      new Vue({        el:'#box',        data:{        },        methods:{        }      });    };  </script><div id="box">    <strong :class="{red:true,blue:true}">文字...</strong>  </div>
<!DOCTYPE html><html lang="en"><head>  <meta charset="UTF-8">  <title></title>  <style>    .red{      color: red;    }    .blue{      background: blue;    }  </style>  <script src="vue.js"></script>  <script>    window.onload=function(){      new Vue({        el:'#box',        data:{          a:true,          b:false        },        methods:{        }      });    };  </script></head><body>  <div id="box">    <strong :class="{red:a,blue:b}">文字...</strong>  </div></body></html>
data:{json:{red:a, blue:false}}

:class="json"

官方推薦用法

<!DOCTYPE html><html lang="en"><head>  <meta charset="UTF-8">  <title></title>  <style>    .red{      color: red;    }    .blue{      background: blue;    }  </style>  <script src="vue.js"></script>  <script>    window.onload=function(){      new Vue({        el:'#box',        data:{          json:{            red:true,            blue:true          }        },        methods:{        }      });    };  </script></head><body>  <div id="box">    <strong :class="json">文字...</strong>  </div></body></html>

style:
:style="[c]"

.red{      color: red;    }<div id="box">    <strong :style="{color:'red'}">文字...</strong>  </div>

:style="[c,d]"

注意: 復合樣式,采用駝峰命名法

<!DOCTYPE html><html lang="en"><head>  <meta charset="UTF-8">  <title></title>  <style></style>  <script src="vue.js"></script>  <script>    window.onload=function(){      new Vue({        el:'#box',        data:{          c:{color:'red'},//這里的red是 class .red          b:{backgroundColor:'blue'}//注意: 復合樣式,采用駝峰命名法        },        methods:{        }      });    };  </script></head><body>  <div id="box">    <strong :style="[c,b]">文字...</strong>  </div></body></html>

:style="json"

<!DOCTYPE html><html lang="en"><head>  <meta charset="UTF-8">  <title></title>  <style></style>  <script src="vue.js"></script>  <script>    window.onload=function(){      new Vue({        el:'#box',        data:{          a:{            color:'red',            backgroundColor:'gray'          }        },        methods:{        }      });    };  </script></head><body>  <div id="box">    <strong :style="a">文字...</strong>  </div></body></html>

希望本文所述對大家vue.js程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 古交市| 溧阳市| 金寨县| 绵阳市| 改则县| 江北区| 张北县| 河源市| 江阴市| 邵东县| 平罗县| 饶阳县| 浮山县| 横峰县| 阳城县| 兰州市| 宜都市| 濉溪县| 大埔区| 南部县| 楚雄市| 仪征市| 西和县| 平顺县| 西宁市| 邹城市| 额济纳旗| 静乐县| 恩平市| 喜德县| 金塔县| 定兴县| 临漳县| 湖北省| 盐边县| 泗洪县| 宣城市| 麻江县| 两当县| 宝鸡市| 奎屯市|