javascript - 如何在Vue中使用不同文件中的函数
问题描述
我是 vue 的新手,我正在尝试使用一个辅助函数,即我导入的其中一个 .vue 文件中的 arrayDateFormatter。我试图在内部使用它,mounted()
但它永远不会被调用,之后什么也没有。我在控制台中没有收到任何错误
我的 vue 文件
<template>
.....
</template>
<script>
import archives from "@/4.objects/o-archives";
import fullBanner from "@/4.objects/o-full-banner";
import speakerInfo from "@/4.objects/o-speaker-info";
import newsletter from "@/4.objects/o-newsletter";
import dataLoaderMixin from "@/mixins/dataLoader-mixin";
import arrayDateFormatter from "../mixins/gloabalEventsDateFormate-mixin";
export default {
components: {
....
},
mixins: [dataLoaderMixin],
data() {
return {
speakers: [],
talkInfo: null,
archives: []
};
},
async mounted() {
try {
const response = await this.fetchEventsByProject();
console.log(response.data.data.listOnlineEvents.items);
//nothing gets triggered after here
const currentEvent = arrayDateFormatter(response);
console.log('current event');
console.log(currentEvent);
this.archives = this.fetchData("archive");
} catch (err) {
return err
}
}
};
</script>
辅助函数
export const arrayDateFormatter = (response)=> {
//some code i have tested and it works by itself
}
解决方案
看起来我必须以这种方式导入文件
import {arrayDateFormatter} from "../mixins/gloabalEventsDateFormate-mixin";
推荐阅读
- node.js - Mongoose 使用 UUID 和 OID 作为 _id
- javascript - React Native:在地图中传递不同的样式
- download - Office JS将文本另存为xml文件失败
- c++ - 从“caml/mlvalues.h”中包装转换宏是否安全,如 Val_int、Int_val 和某些功能?
- go - 使用反射将结构字段动态设置为切片值
- javascript - 如何使用 Vuejs 在单独的页面上显示详细视图
- javascript - 如何重命名数组中的对象键
- javascript - 自动触发 Wordpress 帖子中的“更新”按钮
- python - 通过 pip 安装 qiskit-aer 失败
- angular - 页面加载时的表单输入焦点问题