微信小程序vant用法_开发微信小程序ui组件

(70) 2024-06-27 16:01:03

如题在weap文档上的indexBar是可以点击右侧切换对应索引内容
数字对数字 字符串对字符串

index-bar.js中找到scrollToAnchor函数

scrollToAnchor: function (index) { 
    var _this = this; if (typeof index !== 'number' || this.scrollToAnchorIndex === index) { 
    return; } this.scrollToAnchorIndex = index; var anchor = this.children.find(function (item) { 
    return item.data.index === _this.data.indexList[index]; }); if (anchor) { 
    this.$emit('select', anchor.data.index); wx.pageScrollTo({ 
    duration: 0, scrollTop: anchor.top }); } } 

类型不一致 String !== Number

解决办法:

  1. 把两个类型转换成相同类型则触发判断全等条件就可以正常使用index-bar右侧点击切换啦!
    var anchor = this.children.find(function (item) { 
          return item.data.index === String(_this.data.indexList[index]); }); 

A-Z 0-9
😊今天又是充满希望的一天!

THE END

发表回复