【问题标题】:Can shift a component's function in some other file in vue?可以在 vue 的其他文件中转移组件的功能吗?
【发布时间】:2021-07-24 21:20:48
【问题描述】:

我的 vue 组件中有多个这样的功能。有什么办法可以转移其他文件中的功能,然后将它们导入这里。这是我的App.vue

  getLocation: async function () {
   
    },
    subscribe: function (longitude, latitude) {


    },

    async openLocationWarning() {

     
    },
    uploadData(data, key) {
    
    },
    downloadData()
    {
      
    }

【问题讨论】:

    标签: javascript vue.js vuejs3


    【解决方案1】:

    不,你不能,但你可以使用mixins。也可以保存在js文件中导出。

    export yourFunction() {
    
    }
    
    export anotherFunction(){
    }
    

    并将其导入您的文件中

    import {yourFunction, anotherFunction} from 'path/to/your_file';
    
    methods: {
      callSomeFunction() {
        // you can call it like this.
        yourFunction();
      }
    }
    

    【讨论】:

      最近更新 更多