vue3响应式CSS(真香)

news/2024/7/9 23:49:33 标签: css, html, 前端, vue-cli3, vue
htmledit_views">

我相信很多人在写CSS的时候,突然遇到需要变化的html" title=css>css会使用绑定class样式来实现。这时候就回想如果能定义一个属性并且还是响应式的那就真香了。那么它来了 Vue3

Vue3响应式CSS

 在Vue3中可以再html" title=css>css标签中使用v-bind(***) 来绑定一个属性控制它的样式,注意:【如果你的数据不是使用Vue3的 ref 或者 reactive使其变成响应式,那么则不是响应式的】

<template>
  <div class="son">
    <h3>-----Vue编程式Css</h3>
    <button @click="revampColor">修改背景颜色</button>
  </div>
</template>

<script>
import { ref} from "vue";
export default {
  name: "son",
  setup() {
    // ref写法
    let color = ref("red");
    function revampColor() {
      color.value = "blue";
    }
    return {
      color,
      revampCar,
    };
  },
};
</script>

<style scoped>
.son {
  background: v-bind("color");
// 如果是reactive的对象 写法如下 color:{a:'red'}
// background: v-bind("color.a");
  padding: 10px;
}
</style>

 


 


http://www.niftyadmin.cn/n/1529379.html

相关文章

018.SpringBoot整合ActiveMQ

下载MQ ActiveMQhttps://activemq.apache.org/download-archives.html 解压运行mq.bat 访问mq后台 http://localhost:8161/admin/index.jsp 账号密码admin admin 引入依赖 <!--MQ--> <dependency><groupId>org.springframework.boot</groupId>&l…

Vue3 使用嵌套路由、以及遇到的 Property ‘xxx‘ does not exist on type

一、在Vue3中路由和Vue2的使用区别 首先如果你习惯性的使用this.$router那你肯定会得到一个报错&#xff0c;因为Vue3中是没有了this&#xff0c;使用的是全新的API&#xff0c;所以这时候我们需要引入 Router 中 useRouter 的这个函数 import { defineComponent, reactive} …

基于Antd Vue做的admin 入门demo

逐步学习vue中&#xff0c;以下是实现的一些功能&#xff0c;后续有新的功能也会更新进来 1、多环境配置 Vue WebPack 多环境配置_℡メ㏑╭ァ小凯-CSDN博客 2、全局变量&#xff0c;Store的用法&#xff0c;实现当前Tab位置&#xff0c;路由定位等核心功能 Vue 关于Store的…

uni-app 蓝牙fail property not support、发现不了服务特征值的问题、突然发现微信蓝牙小秘密

一&#xff0c;使用uni-app编译成安卓APP后报错writeBLECharacteristicValue:fail property not support 导致这个报错的原因是&#xff1a;因为APP调用蓝牙API发送指令过快导致&#xff0c;需要在每次调用蓝牙api发送指令的时候加延时器&#xff0c;这样就能解决这个问题&…

Vue WebPack 多环境配置

默认WebPack创建好的配置在config里面 使用process.env.你配置的Key process.env.ADMIN_TABS_KEY 注意点&#xff0c;这个alter或者console.log的时候才能看到值&#xff0c;如果F12调试的话&#xff0c;process报错undefined&#xff0c;就是说F12看不到值&#xff0c;只能在…

uni-app ios跳转京东

uni-app的ios跳转京东领劵功能 需要在manifest.json文件中配置白名单&#xff0c;主要是用作打开其他app "ios" : {"urlschemewhitelist" : "jdlogin,openapp.jdmobile"}废话不多说 上重点&#xff0c; 传参需要经过encodeURL进行转义才行&…

Vue 关于Store的用法

Store就是全局变量都是可以双向绑定的&#xff0c;以下是模块的用法&#xff1a; state定义的是变量名称&#xff0c;mutations里面是给变量赋值的方法 export default {namespaced: true,state: {//打开的Tabstabs: null,//当前显示的keyselectTabKey: null},mutations: {se…

Vue 刷新路由

给路由加个Key&#xff0c;点刷新改变Key即可 <router-view :key"rootkey" />data() {return {//路由的keyrootkey: new Date().getTime(),};},//刷新onReload(icon) {if (icon "redo") {this.rootkey new Date().getTime();}},