帝王谷资源网 Design By www.wdxyy.com
一、用 变量形式 绑定单个 Class 名
在 vue 中绑定单个 class 名还好说,直接写就可以了
<template> <div id="app"> <!-- 因为是自定义属性,所以要用到 v-bind ,简写为 : --> <!-- 3.将 box 绑定给 div --> <div :class="box"></div> </div> </template> <script> export default { name: 'app', data () { return { // 2.在 data 中把 yellow 赋给 box box: 'yellow' } } } </script> <style> /* 1.在样式表中写好样式 */ .yellow{ width: 200px; height: 200px; background: #ff0; } </style>
用 Vue 绑定单个Class 名
二、用 数组形式 绑定多个 Class 名
比如我们想再给这个 div 加个阴影
在 style 中写好样式
.shadow{ box-shadow: 10px 10px 5px 0 #999; }
在 data 中继续添加数据对象
<script> export default { name: 'app', data () { return { box: 'yellow', shadow:'shadow' } } } </script>
在标签中以数组的形式绑定 Class 名
<template> <div id="app"> <div :class="[box,shadow]"></div> </div> </template>
就 OK 了。
用 数组形式 绑定多个 Class 名
三、用 json 形式 绑定多个 Class 名
该方法方便用于当同时添加多个 Class 名时,在某种情况下判断显示哪种样式
先写好样式
<style> .yellow{ width: 200px; height: 200px; background: #ff0; } .shadow{ box-shadow: 10px 10px 5px 0 #999; } </style>
在 data 中添加数字对象,用来做判断
<script> export default { name: 'app', data () { return { show1:true, show2:false } } } </script>
以 json 的形式绑定到 class 中,通过布尔值改变 show1 与 show2 的值,来控制 div 的状态
<template> <div id="app"> <div :class="{yellow:show1,shadow:show2}"></div> </div> </template>
用 json 形式 绑定多个 Class
ps:vue解决跨域问题
改config/index.js文件
proxyTable: { // 请求到 '/device' 下 的请求都会被代理到 target: http://debug.xxx.com 中 '/v1/*': { target: 'https://api.tiaotiao5.com', secure: true, // 接受 运行在 https 上的服务 changeOrigin: true } }
总结
以上所述是小编给大家介绍的使用 Vue 绑定单个或多个 Class 名的实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
帝王谷资源网 Design By www.wdxyy.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
帝王谷资源网 Design By www.wdxyy.com
暂无评论...
更新日志
2024年10月25日
2024年10月25日
- 群星2013-青春缤纷辑压箱宝大公开3CD2[新加坡限量版][WAV整轨]
- 林育群.2013-BalladShow(日本版)【环球】【WAV+CUE】
- 陈加洛.1992-痛到感觉不到【宝丽金】【WAV+CUE】
- 群星.2023-宿命之敌电视剧原声带【韶愔音乐】【FLAC分轨】
- 東京事変-大発見[FLAC+CUE]
- 椎名林檎-三文ゴシップ[FLAC+CUE]
- 2024年08月04日
- 裘德《裘德「最后的水族馆」演唱会LIVE》[320K/MP3][228.89MB]
- 裘德《裘德「最后的水族馆」演唱会LIVE》[24bit 48kHz][FLAC/分轨][2.08G]
- 基因三重奏《如果你什么都不说 音乐会现场录音》[320K/MP3][145.37MB]
- 孟庭苇.1996-月亮说话(2020环球24KGOLD限量版)【上华】【WAV+CUE】
- 群星.1997-新艺宝优质音响系列·国语精选监听版【新艺宝】【WAV+CUE】
- 阿桑.2005-寂寞在唱歌(星外星引进版)【华研国际】【WAV+CUE】
- 基因三重奏《如果你什么都不说 音乐会现场录音》[FLAC/分轨][287.43MB]
- 蔡题谦《我爱你,却依然要看你走》[320K/MP3][88.65MB]