首页 前端知识 vue2/vue3 js变量在<style>标签中使用

vue2/vue3 js变量在<style>标签中使用

2024-01-29 14:01:51 前端知识 前端哥 587 709 我要收藏

此处为scss使用方法

一、vue2

核心::style="{'--color': bgColor}"    将样式变量和js变量关联

            background-color: var(--color);  使用样式变量

<template>
<view class="tabbar">
<view v-for="(item,index) in tabbarData" :key="index" class="item" @click="clickPage(item.url)" :style="{'--color': bgColor}">
<image :src="status==index?item.selected:item.unselected" mode="">
</image>
<view class="text" :style="{color:status==index ? item.activeColor :item.defaultColor}">
{{item.text}}
</view>
</view>
</view>
</template>
<script>
export default {
name: "",
props: {
bgColor: {
type: String,
default: '#fff'
}
}
}
</script>
<style lang="scss" scoped>
.tabbar {
.item {
&:nth-of-type(3) {
border-radius: 50%;
background-color: var(--color);
}
}
}
</style>
复制

二、vue3

核心:let fontcolor = ref('red');  

            color: v-bind(fontcolor);  使用样式变量

<template>
<p>父组件</p>
</template>
<script setup lang="ts">
import { ref } from 'vue';
let fontcolor = ref('red');
</script>
<style lang="scss" scoped>
p{
color: v-bind(fontcolor);
}
</style>
复制

转载请注明出处或者链接地址:https://www.qianduange.cn//article/763.html
标签
评论
还可以输入200
共0条数据,当前/页
发布的文章

HTML5 css3课后习题【一】

2024-02-10 19:02:20

css3 table表格

2024-02-10 19:02:01

CSS 基础知识 选择器

2024-02-10 19:02:50

float,flex和grid布局

2024-02-10 19:02:41

大家推荐的文章
会员中心 联系我 留言建议 回顶部
复制成功!