uniapp 微信小程序一键换肤,走接口,兼容多端!!!

首先使用状态管理,我这是pinia,vuex也是一样的。这样样式就可以通过接口来修改了

import { defineStore } from 'pinia'

export const useSystem = defineStore('system', {
    state: () => ({
        theme: {
            // 深色系主题
            dark: {
                // 文字颜色
                '--text-color': '#ffffff',
                // tab文字颜色
                '--text-color-tab': '#ffffff',
                // tab文字选中颜色
                '--text-color-tab-active': '#000000',
                //tab背景颜色
                '--bg-color-tab': '#000000',
                // 背景颜色
                '--bg-color': '#000000',
                // 边框颜色
                '--border-color': '#0000004d',
            },
            // 浅色系主题
            light: {
                '--text-color': '#000000',
                '--text-color-tab': '#000000',
                '--text-color-tab-active': '#000000',
                '--bg-color-tab': '#ffffff',
                '--bg-color': '#ffffff',
                '--bg-color-tab': '#ffffff',
                '--border-color': '#0000004d',
            },
            // 当前主题
            isDark: false
        }
    }),
    getters: {
        // 主题色
        themeColor() {
            return this.theme.isDark ? this.theme.dark : this.theme.light
        }
    },
    actions: {
        //修改主题色
        changeTheme() {
            this.theme.isDark = !this.theme.isDark
        }
    }
})

然后页面直接使用


<template>
    <view class="tabbar" :style="system.themeColor">
        <view class="tabbar-left">
            <view v-for="(item, index) in tabList" :key="index" @click="go(item.url)" class="tabbar-item">
                <i class="iconfont" :class="[item.icon]"></i>
                <view class="text">{{ item.text }}</view>
            </view>
        </view>
        <!-- #ifdef MP-WEIXIN -->
        <button class="tabbar-right" open-type="contact" bindcontact="handleContact" session-from="sessionFrom">
            <i class="iconfont icon-weixin"></i>
            <view class="text">咨询</view>
        </button>
        <!-- #endif -->
    </view>
</template>
<script setup>
import {useSystem} from "../../store/system"
const system = useSystem()
/* 
 自定义底部菜单栏组件
*/
import { ref } from 'vue'
const tabList = ref([
    {
        icon: 'icon-xitongtuisong',
        text: '发现',
        url: '/pages/index/index'
    },
    {
        icon: 'icon-icon',
        text: '分类',
        url: '/pages/category/index'
    },
    {
        icon: 'icon-shouye',
        text: '客片',
        url: '/pages/album/index'
    },
    {
        icon: 'icon-shouye',
        text: '联系我们',
        url: '/pages/contact/index'
    }
])
const go = (url) => {
    uni.switchTab({
        url
    })
}
</script>
<style lang="scss" scoped>
button {
    all: unset;
}

button::before,
button::after {
    content: none;
}

.tabbar {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: 32rpx;
    z-index: 9999;
    display: flex;
    align-items: center;
    height: 96rpx;
    width: 700rpx;
    font-size: 22rpx;
    color: var(--text-color-tab);

    .iconfont {
        font-size: 44rpx;
    }

    &-left {
        display: flex;
        align-items: center;
        flex: 1;
        background-color: var(--bg-color-tab);
        opacity: .8;
        height: 100%;
        justify-content: space-between;
        padding: 0 32rpx;
        border-radius: 48rpx;

    }

    &-right {
        margin-left: 32rpx;
        width: 160rpx;
        background-color: var(--bg-color-tab);
        opacity: .8;
        justify-content: center;
        align-items: center;
        display: flex;
        flex-direction: column;
        height: 100% !important;
        border-radius: 48rpx;
    }

    &-item {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
    }
}
</style>

最重要的就是 直接 通过 style绑定样式就好了,看了很多版本,发现还是这样最方便,不管是内部样式还是外部样式,都可以直接使用css变量

然后小程序里面就是这样的

 看了很多版本 ,就这个版本兼容多端

h5可以直接使用 document.documentElement.style.setProperty()设置样式,但是不兼容小程序

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
uniapp微信小程序一键登录可以通过使用button组件中的open-type属性来实现。具体步骤如下: 1. 在button组件中设置open-type属性为getUserInfo,同时绑定getuserinfo事件,例如: ```html <button type="default" open-type="getUserInfo" @getuserinfo="wxLogin">一键登录微信小程序</button> ``` 2. 在对应的方法wxLogin中,可以通过event参数获取到用户的信息,包括用户的头像、昵称等。可以将这些信息传递给后端进行处理。 另外,如果需要获取用户的手机号信息,可以使用open-type属性为getPhoneNumber,并绑定getphonenumber事件。具体步骤如下: 1. 在button组件中设置open-type属性为getPhoneNumber,同时绑定getphonenumber事件,例如: ```html <button shape="circle" type="primary" link="true" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">微信一键登录</button> ``` 2. 在对应的方法getPhoneNumber中,可以通过event参数获取到用户的手机号信息。同样,可以将这些信息传递给后端进行处理。 需要注意的是,为了保证前后端的appid一致,以及确保使用的appid是经过认证的,避免出现错误或调用不通的情况。 #### 引用[.reference_title] - *1* [uni-app实现微信小程序一键登录](https://blog.csdn.net/qq_45797421/article/details/118339987)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [uni-app中使用微信一键登录](https://blog.csdn.net/weixin_49296337/article/details/124755651)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值