uni-app

※前提条件:vue3 的uniapp开发

概要 [edit]

以plus开头的方法都是属于HTML5+环境调用的方法。

plus不能在浏览器环境下使用,它必须在手机APP上才能使用

// #ifdef APP-PLUS
var appid = plus.runtime.appid;
console.log('应用的 appid 为:' + appid);
// #endif

API [edit]

getCurrentPages() [edit]

函数用于获取当前页面栈的实例,以数组形式按栈的顺序给出,第一个元素为首页,最后一个元素为当前页面。

export default {
  data() {
    return {
      title: 'Hello'
    }
  },
  onLoad() {
    // #ifdef APP-PLUS
    const currentWebview = this.$scope.$getAppWebview(); //此对象相当于html5plus里的plus.webview.currentWebview()。在uni-app里vue页面直接使用plus.webview.currentWebview()无效
    currentWebview.setBounce({position:{top:'100px'},changeoffset:{top:'0px'}}); //动态重设bounce效果
    // #endif
  }
}

$vm [edit]

当前页面的 Vue 实例

通过页面的 Vue 实例可以获取页面的数据、调用页面上的方法以及监听页面的生命周期等

const page = getCurrentPages()[0];
const vm = page.$vm;
// 监听生命周期,小程序端部分其他生命周期需在页面选项中配置过才可生效
vm.$on('hook:onHide', () => {
  console.log('onHide');
});
// 获取页面数据
console.log(vm.$data.title);
// 调用页面方法
vm.test()

Comment:



(画像の文字列を入力して下さい)

トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS