1、Some selectors are not allowed in component wxss 2、微信小程序点赞效果(点亮小心心)源码

组件模板和样式 | 微信开放文档微信开发者平台文档https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/wxml-wxss.html

微信小程序点赞效果(点亮小心心)源码一并奉上

首先在components里定义了点赞组件,实现效果:

 代码如下:

<!--components/like/index.wxml-->
<view class="container" bindtap="onlike">
  <image src="{{like ? yes : no}}"></image>
  <text>{{count}}</text>
</view>
/* components/like/index.wxss */

.container {
  display: inline-flex;
  flex-direction: row;
  padding: 10rpx;
  width: 190rpx;


}

/* 后代选择器 ,注意这里是可能报错的*/
.container image {
  width: 66rpx;
  height: 66rpx;
}

.container text {
  font-size: 36rpx;
  color: rgb(61, 43, 43);
  position: relative;
  left: 0rpx;
  bottom: 15rpx;
}

/* 屏幕iphone5 的尺寸320*568,那么在高度上rpx会分成568份,每份一个rpx,此时1rpx=1px*/
// components/like/index.js
const app = getApp()

Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    count: 999,
    yes: '/components/like/img/like.png',
    no: '/components/like/img/dislike.png',
    like: false
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onlike() {
      let like = this.properties.like;
      let count = this.properties.count;
      count = like ? count - 1 : count + 1;
      console.log('count like')
      this.setData({
        count,
        like:!like
      })
    }
  }
})

然后报错:

Some selectors are not allowed in component wxss

自定义组件

App 提示:
Some selectors are not allowed in component wxss, including tag name selectors, ID selectors, and attribute selectors.

后来看了别人的文章,改scss,且在微信文档找到了答案。

组件模板和样式 | 微信开放文档微信开发者平台文档https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/wxml-wxss.html

 将css代码改成:

/* components/like/index.wxss */

.container {
  display: inline-flex;
  flex-direction: row;
  padding: 10rpx;
  width: 190rpx;


}

/*改为正常的css选择器名字*/

image {
  width: 66rpx;
  height: 66rpx;
}

text {
  font-size: 36rpx;
  color: rgb(61, 43, 43);
  position: relative;
  left: 0rpx;
  bottom: 15rpx;
}

/* 屏幕iphone5 的尺寸320*568,那么在高度上rpx会分成568份,每份一个rpx,此时1rpx=1px*/

别忘了,usingcomponents

 

  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
以下是一个简单的例子,使用STM32的GPIO口控制8*8 LED点阵。您可以根据自己的需求进行修改。 ```c #include "stm32f10x.h" // 定义引脚 #define LED_LAT_GPIO GPIOA #define LED_LAT_PIN GPIO_Pin_0 #define LED_OE_GPIO GPIOA #define LED_OE_PIN GPIO_Pin_1 #define LED_SCLK_GPIO GPIOA #define LED_SCLK_PIN GPIO_Pin_2 #define LED_SDA_GPIO GPIOA #define LED_SDA_PIN GPIO_Pin_3 // 控制LED点阵的函数 void led_write_byte(unsigned char dat) { unsigned char i; for (i = 0; i < 8; i++) { if (dat & 0x80) { GPIO_SetBits(LED_SDA_GPIO, LED_SDA_PIN); } else { GPIO_ResetBits(LED_SDA_GPIO, LED_SDA_PIN); } dat <<= 1; GPIO_ResetBits(LED_SCLK_GPIO, LED_SCLK_PIN); GPIO_SetBits(LED_SCLK_GPIO, LED_SCLK_PIN); } } void led_write(unsigned char address, unsigned char dat) { GPIO_ResetBits(LED_LAT_GPIO, LED_LAT_PIN); led_write_byte(address); led_write_byte(dat); GPIO_SetBits(LED_LAT_GPIO, LED_LAT_PIN); } void led_init() { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); GPIO_InitStructure.GPIO_Pin = LED_LAT_PIN | LED_OE_PIN | LED_SCLK_PIN | LED_SDA_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_SetBits(LED_LAT_GPIO, LED_LAT_PIN); GPIO_SetBits(LED_OE_GPIO, LED_OE_PIN); GPIO_ResetBits(LED_SCLK_GPIO, LED_SCLK_PIN); GPIO_ResetBits(LED_SDA_GPIO, LED_SDA_PIN); } int main() { led_init(); // 在此处添加要显示的图案的代码 // 例如:led_write(0x00, 0x00); while (1); } ``` 在 `main` 函数中,您可以使用 `led_write` 函数来控制LED点阵。函数的第一个参数表示要写入的地址,第二个参数表示要写入的数据。此外,您还可以在 `led_init` 函数中进行引脚的初始化。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

编程图一乐

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值