大家好,都吃了吗?我是Kaiqisan,是一个不善言辞的羞射男孩。这次解决一下taro的一些架构方面的问题
报错信息
Super expression must either be null or a function
翻译
Super 这个表达式必须为null或是一个函数
报错截图(小程序)
找出问题
import { View } from '@tarojs/components'
import taro from '@tarojs/taro'
export default class Cmp3 extends taro.Component {
constructor(props) {
super(props)
this.state = {}
}
render() {
return <View>
xxxxx
</View>
}
}
问题就出在这个taro.Component,不知道您从何种渠道得知这个写法,只不过它已经过时了,这是taro在1.x,2.x版本的写法,现在taro版本是3.x了。这更新也是为了让开发者可以获得完整的 React/Vue 等框架的开发体验,请大家不要困扰。
大人,时代变了
解决问题
把 taro.Component
替换成 React.Component
import { View } from '@tarojs/components'
import React from 'react'
export default class Cmp3 extends React.Component { // 看这里
constructor(props) {
super(props)
this.state = {}
}
render() {
return <View>
xxxxx
</View>
}
}
总结
教程行不通的话直接去官网找,官网才是权威,教程视频也就图一乐,而且目前B站上那些播放较多的一些教程视频它们有很多使用看着都是今年投稿的,但是却是好几年前录制做的(别问我为什么知道,我之前学习的时候还搜到了两个不同时间段的一个视频,我哭了)