能不能用js改变wxss引用?

小程序 文章 2022-02-07 14:20 398 0 全屏看文

AI助手支持GPT4.0

能不能用js改变wxss引用?Is it possible to change the wxss reference with js?

能不能用js改变wxss引用?

就是在wxss中引用另一份wxss,具体wxss位置由js或wxs控制

比如

@import {{url}}//这个写法肯定不行,有没有能够实现的方法

It refers to another wxss in wxss. The specific wxss location is controlled by JS or WXS. For example, @ import {URL}} / / this writing method is definitely not good. Is there a method that can be implemented

回答:

微喵网络:

不能,要做切换主题,只能通过动态改变class来实现

brave:
// page.wxml<view class="{{theme}}">  <view>content</view></view>// page.jsPage({  data: {    theme: "dark"  }})// app.wxss.light {  color: "#000000"}.dark {  color: "#ffffff"}
Remo筠:不是没想过,但是主题变动的class太多,所以想直接改引用
圣殿骑士:

直接引就行~

Remo筠:问题是我的wxss位置有所变动,类似切换主题,不同主题wxss位置不同,所有需要js去判断当前主题

-EOF-

AI助手支持GPT4.0