uniapp的页面中如何访问App.vue中的方法

<template>
    <view id="k">
        <view class="u-page">
            <uni-page>
                <uni-page-head uni-page-head-type="default" style="background-color: #f1f1f1">
                    <div class="uni-page-head" style="background-color: #f1f1f1;color: rgb(0, 0, 0);">
                        <div class="uni-page-head-hd" style="margin-left: 2%;">
                            <div class="uni-page-head-btn">
                                <i class="uni-btn-icon" @click="loign"
                                    style="color: rgb(0, 0, 0); font-size: 27px;"></i>
                            </div>
                        </div>

上面的代码片段取自某个页面(A)中, 代码中有一个login方法(click绑定的),好多页面都有且代码都一样,把login移至App.vue中了。如下:

<script>
import Cookies from 'js-cookie';
export default {
    onLaunch: function() {
        console.log('App Launch');    
    },
    //扩展函数
    methods:{
           login:function(){ //ETC }
        }

想请教大家的是:现在页面(A)的click中该怎么写呢

阅读 5.6k
2 个回答

在main.js中重复声明了一下,好过于在页面中不断重复

Vue.prototype.appLogin = function(){
    getApp().login();
}

在app里声明全局mixins

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题