New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

miniprogram-rate

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

miniprogram-rate

miniprogram custom component

latest
Source
npmnpm
Version
1.0.7
Version published
Weekly downloads
3
-76.92%
Maintainers
1
Weekly downloads
 
Created
Source

miniprogram-rate

小程序自定义评分组件

使用此组件需要依赖小程序基础库 2.2.1 以上版本,同时依赖开发者工具的 npm 构建。具体详情可查阅官方 npm 文档

使用方法

1.安装 rate

npm install --save miniprogram-rate

2.在需要使用 srate 的页面 page.json 中添加 rate 自定义组件配置

{
  "usingComponents": {
    "rate": "miniprogram-rate"
  }
}

3.WXML 文件中引用 rate

<rate />

##示例

基础示例

评论的个数,只读模式

// wxml
<rate value="{{value}}"  disabled="{{disabled}}" />

// js
  Page({
    data: {
      value: 3,
      disabled: true
    }
  })

评论的star总个数

// wxml
  <rate  count="{{count}}"  />

// js
  Page({
    data: {
      count: 10
    }
  })

显示取消(重置)按键

// wxml
  <rate  cancel="{{cancel}}"/>

// js
  Page({
    data: {
      cancel: true
    }
  })

取消(重置)按键位置(右边)

// wxml
  <rate  cancel="{{cancel}}"  cancelPlace="{{cancelPlace}}"/>

// js
  Page({
    data: {
      cancel: true,
      cancelPlace: 'right'
    }
  })

自定义图标

// wxml
  <rate star-on="{{starOn}}"  star-off="{{starOff}}" />

// js
  Page({
    data: {
      starOn: './img/medal-on.png',
      starOff: './img/medal-off.png'
    }
  })

注意,这边图标的路径,需要根据自己当前项目位置决定

开启自定义一系列图标

// wxml
  <rate  faceIcon="{{faceIcon}}"/>

// js
  Page({
    data: {
      faceIcon: true
    }
  })

自己有默认5个图标,如果需要自己定义的图标可以faceIconArr这个属性来设置: 如下

// wxml
  <rate  faceIcon="{{faceIcon}}"  faceIconArr="{{faceIconArr}}"/>

// js
  Page({
    data: {
      faceIcon: true,
      faceIconArr: ['./img/face-a.png', './img/face-b.png', './img/face-c.png',
        './img/face-d.png', './img/coffee.png', './img/cancel-off.png']
    }
  })

注意: 此时的总个数是没数组的大小决定的, 而不是 count.

change事件

// wxml

  <view class="container">
    <rate  bind:change="change"/>
    <view>{{curentScope}} 分</view>
  </view>

// js
  Page({
    data: {
      curentScope: 0,
    },
    change(event) {
      const curentScope = event.detail.index
      this.setData({
        curentScope
      })
    }
  })

##API

Rate properties

属性说明类型默认值
i-class自定义 class 类名String-
countstar 总数Number5
value当前 star 数Number0
disabled是否只读,无法进行交互Booleanfalse
size图标大小,单位 rpxNumber32
cancel 显示取消按钮来重置 star 数量 Booleanfalse
cancelPlace 取消按钮的位置(left|right) String取消按钮的位置(left
starOn 选中的图标 String'./img/star-on.png'
starOff 未选中的图标 String'./img/star-off.png'
faceIcon 开启定义表情包 Booleanfalse
faceIconArr 定义表情包数组 Array['./img/face-a.png', './img/face-a.png', './img/face-b.png', './img/face-c.png', './img/face-d.png']

Rate events

事件名说明返回值
bind:change点击评分时触发{{index}}
bind:cancel点击重置按钮时触发{{index}}

FAQs

Package last updated on 11 Nov 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts