微信小程序 app.json 里 “style“: “v2“ 的作用

新版微信小程序的app.json引入了style:v2,这代表基础组件样式的升级,如button的效果有所改变。当删除style:v2,可能导致使用vant组件库的页面样式失效。解决方案是在特定页面的.json配置中添加style:v2来保持样式一致。

新版微信小程序的 app.json 文件中多了一个:style": "v2"

{
  "pages":[
    "pages/index/index",
    "pages/logs/logs"
  ],
  "window":{
    "backgroundTextStyle":"light",
    "navigationBarBackgroundColor": "#fff",
    "navigationBarTitleText": "Weixin",
    "navigationBarTextStyle":"black"
  },
  "style": "v2",
  "sitemapLocation": "sitemap.json"
}

在这里插入图片描述

可以看做是微信小程序基础组件样式升级,使用v2版本的组件样式默认情况和v1不同,涉及的组件有6个。

例如 button:

<button type="primary">提交</button>
<button type="primary" loading="true">Loading</button>
<button type="primary" disabled="true">Disabled</button> 

V2版效果如图:

在这里插入图片描述

如果把 “style”: “v2”, 删除,

{
  "pages":[
    "pages/index/index",
    "pages/logs/logs"
  ],
  "window":{
    "backgroundTextStyle":"light",
    "navigationBarBackgroundColor": "#fff",
    "navigationBarTitleText": "Weixin",
    "navigationBarTextStyle":"black"
  },
  "sitemapLocation": "sitemap.json"
}

效果如图:
在这里插入图片描述

还有其他组件的区别,就不一一列举了。

注意:

当使用微信小程序进行开发时,如果使用vant组件库或其他组件,删除 app.json 里面的 “style”: “v2” 时,会导致有的页面部分样式失效。这时候可以把有问题的 .json 后缀的文件里添加上"style": v2就可以了。比如你需要在 user 页面里使用微信提供的默认样式,就在 user.json 里面写上 “style”: “v2”就可以了。

Loading project all files... Loading project all files success Loading project all files... Loading project all files... Loading project all files success Loading project all files success 编译 app.json 编译 ext.json 编译 2 个页面json文件 编译 app.json 编译 ext.json 编译 2 个页面json文件 编译 app.json 编译 ext.json 编译 2 个页面json文件 编译 app.json 编译 ext.json 编译 2 个页面json文件 analyzing codes... ignoring files: project.private.config.json analyzing codes success Ignored by code analyzer: project.private.config.json 编译 app.json 编译 ext.json 编译 2 个页面json文件 analyzing codes... ignoring files: project.private.config.json analyzing codes success Ignored by code analyzer: project.private.config.json analyzing codes... ignoring files: project.private.config.json analyzing codes success Ignored by code analyzer: project.private.config.json getDevCodeByFileList-miniProgram 编译 pages/index/index.wxml 编译 pages/index/index.wxml 编译 pages/logs/logs.wxml 编译 pages/logs/logs.wxml getDevCodeByFileList-miniProgram 编译 app.json 编译 ext.json 编译 2 个页面json文件 getDevCodeByFileList-miniProgram 编译 app.wxss 编译 app.wxss 编译 pages/index/index.wxss 编译 pages/index/index.wxss 编译 pages/logs/logs.wxss 编译 pages/logs/logs.wxss getDevCodeByFileList-miniProgram 编译 app.js 编译 app.js 编译 utils/util.js 编译 utils/util.js getDevCodeByFileList-miniProgram 编译 pages/index/index.js 编译 pages/index/index.js 编译 app.json 编译 ext.json 编译 2 个页面json文件 analyzing codes... ignoring files: project.private.config.json,utils/util.js analyzing codes success Ignored by code analyzer: project.private.config.json,utils/util.js analyzing codes... ignoring files: project.private.config.json,utils/util.js analyzing codes success Ignored by code analyzer: project.private.config.json,utils/util.js 编译 app.json 编译 ext.json 编译 2 个页面json文件 analyzing codes... ignoring files: project.private.config.json analyzing codes success Ignored by code analyzer: project.private.config.json analyzing codes... ignoring files: project.private.config.json analyzing codes success Ignored by code analyzer: project.private.config.json 编译 app.json 编译 ext.json 编译 2 个页面json文件 analyzing codes... ignoring files: project.private.config.json analyzing codes success Ignored by code analyzer: project.private.config.json analyzing codes... ignoring files: project.private.config.json analyzing codes success Ignored by code analyzer: project.private.config.json 编译 app.json app.json: 在项目根目录未找到 app.json 编译 app.json app.json: 在项目根目录未找到 app.json 编译 app.json app.json: 在项目根目录未找到 app.json 编译 app.json app.json: 在项目根目录未找到 app.json 编译 app.json app.json: 在项目根目录未找到 app.json 编译 app.json app.json: 在项目根目录未找到 app.json 编译 app.json app.json: 在项目根目录未找到 app.json 编译 app.json app.json: 在项目根目录未找到 app.json 编译 app.json app.json: 在项目根目录未找到 app.json 编译 app.json app.json: 在项目根目录未找到 app.json 编译 app.json app.json: 在项目根目录未找到 app.json 编译 app.json app.json: 在项目根目录未找到 app.json 编译 app.json app.json: 在项目根目录未找到 app.json 正在编译代码 analyzing codes... ignoring files: project.private.config.json analyzing codes success 编译打包小程序 编译 JSON 文件 app.json: 在项目根目录未找到 app.json app.json: 在项目根目录未找到 app.json
最新发布
07-26
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值