为什么添加了对应的调用函数,点击进度条组件还是无法累加?

来源:2-16 基础组件 - progress

兰柯万

2023-11-10

添加了addPercent函数,但是点击addPercent无法累加,望老师指点

无法累加
basic.wxml 代码片段

<!-- basic.wxml -->
<icon type="success" size="66" color="blue "></icon>
<icon type="success_no_circle" size="66" ></icon>
<icon type="info" size="66" ></icon>
<icon type="warn" size="66" ></icon>
<icon type="waiting" size="66" ></icon>
<icon type="cancel" size="66" ></icon>
<icon type="download" size="66" ></icon>
<icon type="search" size="66" ></icon>
<icon type="clear" size="66" ></icon>

<view>
  <view>这是一个view文本内容</view>
  <text selectable="{{true}}">这是一段\t文本\n内容</text>
</view>
<view>
  <text space="{{true}}">space    空格          内容</text>
</view>
<view>
  <text decode="{{true}}">&nbsp; &lt; &gt; &amp; &apos; &ensp; &emsp;</text>
</view>

<rich-text nodes="{{mycontent}}"></rich-text>
<rich-text nodes="{{mycontent2}}"></rich-text>

<progress percent="42" show-info="true" stroke-width="20"
color="" activeColor="red" backgroundColor="blue" active="true">
</progress>
<progress percent="{{myprecent}}" show-info="true" stroke-width="20"  active-mode="forwards">
</progress>
<view bind:tap="addPercent">addPrercent</view>

basic.js 代码片段

// basic.js

Page({
  data: {
    iconSize: [20, 30, 40, 50, 60, 70],
    iconColor: [
      'red', 'orange', 'yellow', 'green', 'rgb(0,255,255)', 'blue', 'purple'
    ],
    iconType: [
      'success', 'success_no_circle', 'info', 'warn', 'waiting', 'cancel', 'download', 'search', 'clear'
    ],
    mycontent : '<img class="course-banner" src="//img1.sycdn.imooc.com/szimg/623931dc09c59e7600000000.png" />',
    mycontent2 : [
        {
          name: "img",
          attrs: {
            class: "course-banner",
            src: "//img1.sycdn.imooc.com/szimg/623931dc09c59e7600000000.png"
          }
        }
    ],
    myprecent : 15,
    addPercent: function() {
      var newPercent = this.data.myprecent + 20;
      this.setData({
        myprecent: newPercent
      })
    }
  }
})

写回答

1回答

风间影月

2023-11-10

看下你的这个函数能不能一步步执行。打log看下,另外看看有么有报错 ,没有报错说明逻辑控制错了噢

1
1
兰柯万
找到原因了,我把addPercent函数写到data里面了,所以调用的时候找不到函数
2023-11-13
共1条回复

Spring Boot短视频小程序开发 全栈式实战项目

一门课程带你搞定短视频小程序全栈开发,毕业设计之利器!

2613 学习 · 1951 问题

查看课程