TypeError: x is not a function嘗試getPriceInitiator從另一個 .Vue 檔案呼叫時,我得到一個。
<template>
<div id="container">
<p style="color: red">{{ apiCallResponse }}</p>
</div>
</template>
<script>
import { SfButton } from "@storefront-ui/vue";
import { getExternalPrice } from "~/serverMiddleware/customExtension/index.js";
export default {
name: "intergration",
components: {
SfButton,
},
data() {
return {
apiCallResponse: "",
exampleUserId: "[email protected]",
exampleProductId: 1234,
};
},
methods: {
getPriceInitiator(userId, productId) {
getExternalPrice(userId, productId)
.then((data) => {
this.apiCallResponse = "€" data.key;
})
.catch((err) => console.log(err));
},
},
};
</script>
<style lang="scss" scoped>
.h1 {
color: red;
}
</style>
我使用它如下:
import { getPriceInitiator } from "~/plugins/intergration.vue";
export default defineComponent({
name: "ProductPage",
components: {
...
},
mounted() {
this.infoLoggerMethodForDebugging();
},
methods: {
infoLoggerMethodForDebugging() {
console.log("test");
getPriceInitiator("value1", "value2");
},
},
(當我注釋掉 getPriceInitiator 時,它沒有給出任何錯誤)
uj5u.com熱心網友回復:
為您的全域方法創建一個單獨的 .js 檔案。
import { getExternalPrice } from "~/serverMiddleware/customExtension/index.js";
export const getPriceInitiator = (userId, productId) => {
getExternalPrice(userId, productId)
.then((data) => {
this.apiCallResponse = `€${data.key}`;
})
.catch((err) => console.log(err));
};
export default {
getPriceInitiator,
};
然后在你要使用的組件中匯入
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/473071.html
