-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
yarn dev:rn 时 报错 TypeError: TypeError: undefined is not an object (evaluating 'this.$router.params') #1779
Comments
欢迎提交 Issue~ 如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏 如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。 Good luck and happy coding~ |
CC @Pines-Cheng |
我代码里边也没有使用 this.$router.params 获取路由参数 |
方便贴一下首页代码吗?@zhangjie1314 |
这是转换成rn后的 var _class, _temp;
import TaroRouter from '@tarojs/taro-router-rn';
import pagesCvFailIndex from './pages/cv-fail/index';
import pagesCvSuccessIndex from './pages/cv-success/index';
import pagesIntegralOrderListIndex from './pages/integral-order-list/index';
import pagesTicketOrderListIndex from './pages/ticket-order-list/index';
import pagesInputVcodeIndex from './pages/input-vcode/index';
import pagesForgetPasswordIndex from './pages/forget-password/index';
import pagesIndexIndex from './pages/index/index';
import pagesLoginIndex from './pages/login/index';
import Taro from '@tarojs/taro-rn';
import React from 'react';
import appStyleSheet from "./app_styles";
var _styleSheet = appStyleSheet;
let App = (_temp = _class = class App extends React.Component {
// componentWillMount() {
// this.$app.globalData = this.globalData
// }
render() {
return <RootStack />;
}
}, _class.config = {
// subPackages: [
// {
// root: 'packages/store',
// pages: [
// 'index/index',
// 'cv-success/index',
// 'cv-fail/index',
// 'order-list/index',
// 'input-vcode/index'
// ]
// }
// ],
window: {
navigationBarBackgroundColor: '#fff',
navigationBarTitleText: '商务服务平台',
navigationBarTextStyle: 'black'
} }, _temp); //app.js
export default App;
const RootStack = TaroRouter.initRouter([['pages/login/index', pagesLoginIndex], ['pages/index/index', pagesIndexIndex], ['pages/forget-password/index', pagesForgetPasswordIndex], ['pages/input-vcode/index', pagesInputVcodeIndex], ['pages/ticket-order-list/index', pagesTicketOrderListIndex], ['pages/integral-order-list/index', pagesIntegralOrderListIndex], ['pages/cv-success/index', pagesCvSuccessIndex], ['pages/cv-fail/index', pagesCvFailIndex]], Taro, App.config);
Taro.initNativeApi(Taro);
Taro.initPxTransform({
"designWidth": 750,
"deviceRatio": {
"640": 1.17,
"750": 1,
"828": 0.905
}
}); 这是转换成rn后的首页 var _dec, _class, _class2, _temp2;
import Taro from '@tarojs/taro-rn';
import { Block, View, Form, RadioGroup, Radio, Input, Navigator, Button } from "@tarojs/components-rn";
import React from 'react';
import withWeapp from '@tarojs/with-weapp';
// pages/login/index.js
import _ from '../../utils/util.js';
import Apis from '../../utils/apis.js';
import indexStyleSheet from "./index_styles";
var _styleSheet = indexStyleSheet;
let _C = (_dec = withWeapp('Page'), _dec(_class = (_temp2 = _class2 = class _C extends React.Component {
constructor(...args) {
var _temp;
return _temp = super(...args), this.state = {
platformArr: [{ value: 1, text: '景区', selected: true }, { value: 2, text: '商户', selected: false }], // 可选平台数据
curSelectedPlatform: 1 // 当前选中的平台
}, this.loginFun = e => {
let params = {
u: e.detail.value.user_name,
p: e.detail.value.password
};
let url = '';
if (this.data.curSelectedPlatform == 1) {
url = Apis.login;
} else {
url = Apis.storeLogin;
}
_.request(url, 'post', params).then(res => {
// 本地保存登录信息
Taro.setStorageSync('userInfo', res.data);
// 跳转去首页
if (this.data.curSelectedPlatform == 1) {
// 跳转景区管理首页
Taro.redirectTo({
url: '../index/index'
});
} else {
// 跳转商户管理首页
Taro.redirectTo({
url: '/packages/store/index/index'
});
}
});
}, this.selectionPlatformFun = e => {
this.setData({
curSelectedPlatform: e.detail.value
});
}, this.onShareAppMessage = () => {
return {
title: '智慧景区服务平台',
imageUrl: 'https://scenic.tuliyou.com/static/images/scenic_server_share_img.jpeg'
};
}, _temp;
}
componentWillMount() {
const userInfo = Taro.getStorageSync('userInfo');
// 检测是否登录
if (userInfo) {
// 检测登录信息是否为景区管理员登录
if (userInfo.sid) {
// 跳转景区管理首页
Taro.redirectTo({
url: 'pages/index/index'
});
} else {
// 跳转商户管理首页
Taro.redirectTo({
url: '/packages/store/index/index'
});
}
}
}
render() {
const {
platformArr: platformArr,
curSelectedPlatform: curSelectedPlatform
} = this.state;
return <Block>
{}
<View style={_styleSheet["login-box"]}>
<View style={_styleSheet["title"]}>景区商务服务平台</View>
<Form onSubmit={this.loginFun}>
<View style={_styleSheet["selection-platform"]}>
<RadioGroup onChange={this.selectionPlatformFun}>
{platformArr.map((item, index) => {
return <Radio value={item.value} checked={item.selected} key="index" color="#229fff" style={_styleSheet["radio"]}>
{item.text}
</Radio>;
})}
</RadioGroup>
</View>
<Input type="text" placeholder="用户名" placeholderClass="place-style" name="user_name" />
<Input type="password" placeholder="密码" placeholderClass="place-style" name="password" />
<View style={_styleSheet["small-btn-box"]}>
{curSelectedPlatform == 1 && <Navigator openType="navigate" url="../forget-password/index" style={_styleSheet["forget-password"]}>
忘记密码?
</Navigator>}
</View>
<View style={_styleSheet["btn-box"]}>
<Button formType="submit" style={_styleSheet["login-brn"]}>
登录
</Button>
</View>
</Form>
</View>
</Block>;
}
}, _class2.config = {}, _temp2)) || _class);
export default _C; |
@zhangjie1314 我指的是转换前的代码哦~ |
import {
Block,
View,
Form,
RadioGroup,
Radio,
Input,
Navigator,
Button
} from '@tarojs/components'
import Taro from '@tarojs/taro'
import withWeapp from '@tarojs/with-weapp'
// pages/login/index.js
import _ from '../../utils/util.js'
import Apis from '../../utils/apis.js'
import './index.scss'
@withWeapp('Page')
class _C extends Taro.Component {
state = {
platformArr: [
{ value: 1, text: '景区', selected: true },
{ value: 2, text: '商户', selected: false }
], // 可选平台数据
curSelectedPlatform: 1 // 当前选中的平台
}
componentWillMount() {
const userInfo = Taro.getStorageSync('userInfo')
// 检测是否登录
if (userInfo) {
// 检测登录信息是否为景区管理员登录
if (userInfo.sid) {
// 跳转景区管理首页
Taro.redirectTo({
url: '../index/index'
})
} else {
// 跳转商户管理首页
Taro.redirectTo({
url: '/packages/store/index/index'
})
}
}
}
loginFun = e => {
let params = {
u: e.detail.value.user_name,
p: e.detail.value.password
}
let url = ''
if (this.data.curSelectedPlatform == 1) {
url = Apis.login
} else {
url = Apis.storeLogin
}
_.request(url, 'post', params).then(res => {
// 本地保存登录信息
Taro.setStorageSync('userInfo', res.data)
// 跳转去首页
if (this.data.curSelectedPlatform == 1) {
// 跳转景区管理首页
Taro.redirectTo({
url: '../index/index'
})
} else {
// 跳转商户管理首页
Taro.redirectTo({
url: '/packages/store/index/index'
})
}
})
}
selectionPlatformFun = e => {
this.setData({
curSelectedPlatform: e.detail.value
})
}
onShareAppMessage = () => {
return {
title: '智慧景区服务平台',
imageUrl:
'https://scenic.tuliyou.com/static/images/scenic_server_share_img.jpeg'
}
}
config = {}
render() {
const {
platformArr: platformArr,
curSelectedPlatform: curSelectedPlatform
} = this.state
return (
<Block>
{/* pages/login/index.wxml */}
<View className="login-box">
<View className="title">景区商务服务平台</View>
<Form onSubmit={this.loginFun}>
<View className="selection-platform">
<RadioGroup onChange={this.selectionPlatformFun}>
{platformArr.map((item, index) => {
return (
<Radio
className="radio"
value={item.value}
checked={item.selected}
key="index"
color="#229fff"
>
{item.text}
</Radio>
)
})}
</RadioGroup>
</View>
<Input
type="text"
placeholder="用户名"
placeholderClass="place-style"
name="user_name"
/>
<Input
type="password"
placeholder="密码"
placeholderClass="place-style"
name="password"
/>
<View className="small-btn-box">
{curSelectedPlatform == 1 && (
<Navigator
openType="navigate"
url="../forget-password/index"
className="forget-password"
>
忘记密码?
</Navigator>
)}
</View>
<View className="btn-box">
<Button formType="submit" className="login-brn">
登录
</Button>
</View>
</Form>
</View>
</Block>
)
}
}
export default _C |
这个是首页的 |
这个是 import Taro from '@tarojs/taro'
import './app.scss'
class App extends Taro.Component {
config = {
pages: [
'pages/login/index',
'pages/index/index',
'pages/forget-password/index',
'pages/input-vcode/index',
'pages/ticket-order-list/index',
'pages/integral-order-list/index',
'pages/cv-success/index',
'pages/cv-fail/index'
],
// subPackages: [
// {
// root: 'packages/store',
// pages: [
// 'index/index',
// 'cv-success/index',
// 'cv-fail/index',
// 'order-list/index',
// 'input-vcode/index'
// ]
// }
// ],
window: {
navigationBarBackgroundColor: '#fff',
navigationBarTitleText: '商务服务平台',
navigationBarTextStyle: 'black'
}
}
// componentWillMount() {
// this.$app.globalData = this.globalData
// }
render() {
return null
}
} //app.js
export default App
Taro.render(<App />, document.getElementById('app')) |
好的,非常感谢~🙏 |
原因已找到,@withWeapp 装饰器导致的,正在修复。 |
好的 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
问题描述
运行 dev:rn 时出现如题报错
报错信息
系统信息
The text was updated successfully, but these errors were encountered: