Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

小程序引用老虎机组件报错 #313

Closed
liuhui1999 opened this issue Aug 18, 2022 · 12 comments
Closed

小程序引用老虎机组件报错 #313

liuhui1999 opened this issue Aug 18, 2022 · 12 comments

Comments

@liuhui1999
Copy link

liuhui1999 commented Aug 18, 2022

  • 你当前是什么框架(必填):taro

  • 你使用的是哪个包(必填):"@lucky-canvas/taro"

  • 你当前插件的版本(必填): "^0.0.12",

  • 当前环境是小程序还是浏览器(选填):taro

  • 详细描述你的bug:
    小程序引用老虎机组件报错

image

image

  • 问题代码(重要):

export default SlotMachiner;
// 代码开始, 别再放歪了行吗
import React, { Component } from 'react';
import { SlotMachine } from '@lucky-canvas/taro/react'
import { View } from '@tarojs/components';
class SlotMachiner extends Component {
myLucky: any
constructor(props) {
super(props);
this.myLucky = React.createRef()
}
playGame = () => {
this.myLucky.current.play()
setTimeout(() => {
// 假设 4 种结果
const res = [
[9, 9, 6],
[0, 0, 7],
[6, 6, 6],
[8, 8, 8]
]
// 随机取一组数据
const index = res[Math.random() * 4 >> 0]
// 调用 stop 方法停止游戏
this.myLucky.current.stop(index)
}, 500);
}
render() {
return (
<>
<SlotMachine
ref={this.myLucky}
width={240}
height={180}
blocks={[
{ padding: '10px', background: '#617df2' },
{ padding: '10px', background: '#869cfa' },
{ padding: '10px', background: '#afc8ff' },
{ padding: '10px', background: '#e9e8fe' },
]}
>

<View onClick={() => this.playGame()}>开始抽奖
</>
);
}
}

export default SlotMachiner;
// 代码结束

@buuing
Copy link
Owner

buuing commented Aug 18, 2022

我都服了, 你看不到代码块的开始和结束吗, 这也能放歪?

@liuhui1999
Copy link
Author

我都服了, 你看不到代码块的开始和结束吗, 这也能放歪?

问题不大 咋回事老哥

@buuing
Copy link
Owner

buuing commented Aug 18, 2022

问题很大, 你重新编辑一下, 这代码都扭曲到一起了怎么看

@liuhui1999
Copy link
Author

问题很大, 你重新编辑一下, 这代码都扭曲到一起了怎么看
ok

@buuing
Copy link
Owner

buuing commented Aug 18, 2022

顺便提供taro的版本信息, 小程序基准库, 最好是发个能复现问题的demo

@liuhui1999
Copy link
Author

顺便提供taro的版本信息, 小程序基准库, 最好是发个能复现问题的demo

https://github.com/liuhui1999/Lucky-demo

@buuing
Copy link
Owner

buuing commented Aug 18, 2022

你这代码写的是什么?你在箭头函数里使用this?你在搞笑?

@liuhui1999
Copy link
Author

你这代码写的是什么?你在箭头函数里使用this?你在搞笑?

image
image

@buuing
Copy link
Owner

buuing commented Aug 19, 2022

嗯? 还报错? 奇怪

@buuing
Copy link
Owner

buuing commented Aug 19, 2022

说一下你taro的版本和小程序基准库的版本

@liuhui1999
Copy link
Author

说一下你taro的版本和小程序基准库的版本

"dependencies": {
"@babel/runtime": "^7.7.7",
"@lucky-canvas/taro": "^0.0.12",
"@tarojs/components": "3.5.2",
"@tarojs/extend": "^3.4.7",
"@tarojs/plugin-framework-react": "3.5.2",
"@tarojs/react": "3.5.2",
"@tarojs/runtime": "3.5.2",
"@tarojs/taro": "3.5.2",
"dayjs": "1.9.6",
"react": "^17.0.0",
"react-dom": "^17.0.0",
"taro-code": "^3.5.2",
"taro-ui": "^3.1.0-beta.3"
},
"devDependencies": {
"@babel/core": "^7.8.0",
"@tarojs/mini-runner": "3.5.2",
"@tarojs/webpack-runner": "3.5.2",
"@types/react": "^17.0.2",
"@types/webpack-env": "^1.13.6",
"@typescript-eslint/eslint-plugin": "^4.15.1",
"@typescript-eslint/parser": "^4.15.1",
"babel-preset-taro": "3.5.2",
"eslint": "^6.8.0",
"eslint-config-taro": "3.5.2",
"eslint-plugin-import": "^2.12.0",
"eslint-plugin-react": "^7.8.2",
"eslint-plugin-react-hooks": "^4.2.0",
"stylelint": "^14.4.0",
"taro-iconfont-cli": "^3.3.0",
"typescript": "^4.1.0"
}

image

@buuing
Copy link
Owner

buuing commented Aug 27, 2022

排查完毕, width={240}改成width={'240px'}, height同理

但是这种数字的方式也可以支持一下, 今晚会发个新版兼容一下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants