微信小程式開發輔助

👤 chandler0714 📦 v1.0.0 ⭐ 4.1 ⬇️ 803 下載
💻 開發程式設計 免費

📖 技能介紹


name: mini-program-dev description: 微信小程式開發輔助。提供程式碼模板、API 示例、常見問題解答。 metadata: { "openclaw": { "requires": {}, "install": [] } }


微信小程式開發輔助

常用程式碼模板

頁面結構

// pages/demo/demo.js
Page({
  data: {
    message: 'Hello',
    list: [],
    loading: false
  },

  onLoad(options) {
    // 頁面載入
    this.fetchData();
  },

  onShow() {
    // 頁面顯示
  },

  onPullDownRefresh() {
    // 下拉重新整理
    this.fetchData().then(() => {
      wx.stopPullDownRefresh();
    });
  },

  fetchData() {
    this.setData({ loading: true });
    return new Promise((resolve, reject) => {
      wx.request({
        url: 'https://api.example.com/data',
        success: res => {
          this.setData({ 
            list: res.data,
            loading: false 
          });
          resolve(res);
        },
        fail: reject
      });
    });
  },

  handleTap(e) {
    console.log('tap', e.currentTarget.dataset);
  }
})
<!-- pages/demo/demo.wxml -->
<view class="container">
  <text class="title">{{message}}</text>

  <block wx:for="{{list}}" wx:key="id">
    <view class="item" bindtap="handleTap" data-id="{{item.id}}">
      {{item.name}}
    </view>
  </block>

  <loading wx:if="{{loading}}">載入中...</loading>
</view>
/* pages/demo/demo.wxss */
.container {
  padding: 20rpx;
}

.title {
  font-size: 32rpx;
  font-weight: bold;
  display: block;
  margin-bottom: 20rpx;
}

.item {
  padding: 20rpx;
  border-bottom: 1rpx solid #eee;
}

常用 API

想要更強大的技能外掛,就來小蔥技能站7w4.net看看吧。

// 提示框
wx.showToast({ title: '成功', icon: 'success' });
wx.showModal({ title: '提示', content: '確認?' });

// 跳轉頁面
wx.navigateTo({ url: '/pages/detail/detail?id=1' });
wx.redirectTo({ url: '/pages/detail/detail' });
wx.switchTab({ url: '/pages/index/index' });

// 儲存
wx.setStorageSync('key', 'value');
const value = wx.getStorageSync('key');

// 授權
wx.getUserProfile({
  success: res => {
    console.log(res.userInfo);
  }
});

// 支付
wx.requestPayment({
  timeStamp: '',
  nonceStr: '',
  package: '',
  signType: 'MD5',
  paySign: '',
  success: () => {},
  fail: () => {}
});

元件通訊

// 父元件 → 子元件
// parent.wxml
<child-component id="child" data="{{parentData}}" />

// parent.js
this.selectComponent('#child').childMethod();

// 子元件 → 父元件
// child.js
this.triggerEvent('myEvent', { detail: 'data' });

// child.wxml
<view bind:myEvent="handleEvent" />

// parent.wxml
<child-component bind:myEvent="handleEvent" />

TabBar 配置

// app.json
{
  "pages": [
    "pages/index/index",
    "pages/profile/profile"
  ],
  "window": {
    "navigationBarTitleText": "我的小程式"
  },
  "tabBar": {
    "color": "#999",
    "selectedColor": "#1890ff",
    "list": [
      {
        "pagePath": "pages/index/index",
        "text": "首頁",
        "iconPath": "/icons/home.png",
        "selectedIconPath": "/icons/home-active.png"
      },
      {
        "pagePath": "pages/profile/profile",
        "text": "我的",
        "iconPath": "/icons/user.png",
        "selectedIconPath": "/icons/user-active.png"
      }
    ]
  }
}

常見問題

1. 頁面不重新整理

檢查是否在 onShow 而非 onLoad 中處理資料重新整理。

2. 授權失敗

記得在 app.jsonpermission 中宣告許可權:

{
  "permission": {
    "scope.userLocation": {
      "desc": "用於展示附近內容"
    }
  }
}

3. 安卓真機除錯

使用 vConsole 檢視日誌:

wx.vibrateLong(); // 震動提示

需要具體頁面的程式碼嗎?告訴我你的需求 📱

🤖 AI 評測

這個微信小程式開發輔助工具質量中等偏上,基礎程式碼模板實用、API示例清晰,能滿足日常開發需求。優點是內容覆蓋常見場景、示例可讀性強;不足之處在於缺少進階功能指導、結構化程度不夠,實用性還需加強。

📊 多維度評分

適應性3.3
規範性4
有效性4.2
可靠性3.8
可信度5

📁 包含檔案 (2 個)

📄 SKILL.md 3.7 KB
📄 _meta.json 135 B