taro开发小程序使用自定义返回的时候 onClick={() => { Taro.redirectTo({ url: '/subPackages3/pages/buy/commodity/index', }) }},返回到上个页面,为什么上个页面要返回两次才返回到上一个页面
时间: 2024-03-03 21:53:57 浏览: 22
这可能是因为你在使用 Taro.redirectTo 方法进行页面跳转时,它会关闭当前页面并打开新页面,从而导致上一个页面被隐藏。所以当你想要返回上一个页面时,需要先返回到上一个页面的上一个页面,然后再返回到上一个页面。
如果你想要直接返回上一个页面而不需要返回两次,可以尝试使用 Taro.navigateBack 方法进行页面返回。这个方法可以直接返回到上一个页面,而不需要先返回到上一个页面的上一个页面。例如:
```
onClick={() => {
Taro.navigateBack();
}}
```
希望能够帮助你解决问题。
相关问题
linux编译taro微信小程序正在编译...EACCES: permission denied, mkdir '/dist'
这个错误提示表明你没有足够的权限在根目录下创建 `/dist` 目录,因此编译过程失败了。可以尝试在命令前加上 `sudo` 以管理员权限运行,或者在其他有写入权限的目录下创建 `/dist` 目录并将编译结果输出到该目录中。例如,可以尝试在项目根目录下创建 `build` 目录,并在命令中指定输出目录:
```
mkdir build
npm run build -- --output-path=./build
```
这将把编译结果输出到 `build` 目录中。如果还是无法解决问题,建议查看你的文件系统权限设置,确保你有足够的权限进行写入操作。
import React, { useState, useCallback } from "react"; import Taro from "@tarojs/taro"; import { View } from "@tarojs/components"; import { LgPopLayer, LgButton } from "lancoo-ui-mobile"; import "../index.scss"; export const Jsx = () => { const [isOpen, setIsOpen] = useState(false); const handleLayer = useCallback(() => { setIsOpen(!isOpen); }, [isOpen]); const confirm = useCallback(() => { Taro.showToast({ title: "点击确定", icon: "none" }); handleLayer(); }, [handleLayer]); return ( <View className="iframe__viewport"> <View className="viewport__title">向下弹出</View> <View className="viewport__main"> <LgButton onClick={handleLayer}>显示上方弹出层</LgButton> <LgPopLayer position="top" isOpen={isOpen} confirm={confirm} showLayer={handleLayer} > <View className="lg-poplayer__content">自定义内容</View> </LgPopLayer> </View> </View> ); }; 改成类组件写法
import React, { Component } from "react";
import Taro from "@tarojs/taro";
import { View } from "@tarojs/components";
import { LgPopLayer, LgButton } from "lancoo-ui-mobile";
import "../index.scss";
class Jsx extends Component {
constructor(props) {
super(props);
this.state = {
isOpen: false
};
}
handleLayer = () => {
this.setState((prevState) => ({
isOpen: !prevState.isOpen
}));
};
confirm = () => {
Taro.showToast({ title: "点击确定", icon: "none" });
this.handleLayer();
};
render() {
const { isOpen } = this.state;
return (
<View className="iframe__viewport">
<View className="viewport__title">向下弹出</View>
<View className="viewport__main">
<LgButton onClick={this.handleLayer}>显示上方弹出层</LgButton>
<LgPopLayer
position="top"
isOpen={isOpen}
confirm={this.confirm}
showLayer={this.handleLayer}
>
<View className="lg-poplayer__content">自定义内容</View>
</LgPopLayer>
</View>
</View>
);
}
}
export default Jsx;