微信小程序实现输入appid跳转其他小程序

前言

本文记录wx.navigateToMiniProgram打开另一个小程序API使用方法,并封装为组件。

wxml 部分

输入框用来记录appid,按钮用来查询并跳转。

<view class="container">
    <input class="input" placeholder="请输入要查询的appid" bindinput="inputAppid" />
    <button class="button" bindtap="detectAppid">查询</button>
</view>

js 部分

设置appid,并绑定检测appid并跳转方法。

Page({
    data: {
        appid: ''
    },
    inputAppid(e) {
        this.setData({
            appid: e.detail.value
        });
    },
    detectAppid() {
        const appid = this.data.appid;
        wx.navigateToMiniProgram({
            appId: appid,
            success(res) {
                console.log('跳转成功', res);
            },
            fail(err) {
                console.error('跳转失败', err);
            }
        });
    }
});

json 部分

通过在小程序页面的 json 文件中navigationBarTitleText字段来设置小程序每个特定页面标题。

{
  "usingComponents": {},
  "navigationBarTitleText": "查询appid"
}

wxss 部分

设置输入框和按钮样式。

20240405225445

/* components/detect-appid/detect-appid.wxss */
.container {
    margin: 10rpx;
}

.input {
    width: 600rpx;
    height: 60rpx;
    padding: 5rpx;
    margin: 10rpx auto;
    border: 1rpx solid #ccc;
}

.button {
    margin-top: 20rpx;
    width: 400rpx;
    padding: 5rpx 5rpx;
    background-color: #007bff;
    color: #fff;
    border: none;
}

最终效果

输入 appid,点击查询后会弹窗提示要跳转的小程序名称,点击允许会跳转至对应appid小程序默认页面。

20240405225525


这里是松桑的前端后花园,目前坚持在写前端后花园周刊,专注前端基础领域,分享常见前端面试题、前端开源项目、工具库、前端最新动态,目前还一个前端菜鸟,和我一起打怪升级吧!这里是我精选的往期文章,希望对你有所帮助。

Node.js常用命令及学习资料

18个宝藏技术周刊,涵盖前端、产品、UX、AIGC、独立开发、科技(偷偷收藏)

为什么每个自媒体人都需要个人网站?(附十分钟快速建站教程)

我用 Nextjs 十分钟搭建了一个展示955公司网站

Gitbook 小书 - 快速创建你的个人专栏

相关推荐

  1. 程序页面

    2024-04-11 14:30:04       63 阅读
  2. 程序webView

    2024-04-11 14:30:04       41 阅读
  3. 程序到外部程序

    2024-04-11 14:30:04       60 阅读
  4. 程序页面方法

    2024-04-11 14:30:04       63 阅读
  5. 程序如何到网页

    2024-04-11 14:30:04       52 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-11 14:30:04       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-11 14:30:04       101 阅读
  3. 在Django里面运行非项目文件

    2024-04-11 14:30:04       82 阅读
  4. Python语言-面向对象

    2024-04-11 14:30:04       91 阅读

热门阅读

  1. 如何使用pandoc转word和正确的参考文献格式

    2024-04-11 14:30:04       27 阅读
  2. AcWing 793. 高精度乘法——算法基础课题解

    2024-04-11 14:30:04       35 阅读
  3. node 的路径分析和文件查找策略

    2024-04-11 14:30:04       35 阅读
  4. 问题整理【2024-04-10】

    2024-04-11 14:30:04       33 阅读
  5. 【C++01】吾与C加初相识

    2024-04-11 14:30:04       28 阅读
  6. 从零开始的LeetCode刷题日记:28. 实现 strStr()

    2024-04-11 14:30:04       42 阅读
  7. 医美行业专用服务器:为您的业务保驾护航

    2024-04-11 14:30:04       35 阅读
  8. 二进制转十进制快速方法

    2024-04-11 14:30:04       30 阅读
  9. 美国发布玩具安全标准ASTM F963-23

    2024-04-11 14:30:04       34 阅读
  10. Vue 的父组件和子组件生命周期钩子函数执行顺序

    2024-04-11 14:30:04       32 阅读