我正在try 通过Gpay在vue js中使用Google—pay—button支付集成.但我收到警告—Failed to resolve component: google-pay-button

我的密码—

<google-pay-button
    environment="TEST"
    v-bind:button-type="buttonType"
    v-bind:button-color="buttonColor"
    v-bind:existing-payment-method-required="existingPaymentMethodRequired"
    v-bind:paymentRequest.prop="{
        apiVersion: paymentRequest.apiVersion,
        apiVersionMinor: paymentRequest.apiVersionMinor,
        allowedPaymentMethods: paymentRequest.allowedPaymentMethods,
        merchantInfo: paymentRequest.merchantInfo,
        transactionInfo: transactionInfo,
        callbackIntents: callbackIntents,
    }"
    v-on:loadpaymentdata="onLoadPaymentData"
    v-on:error="onError"
    v-bind:onPaymentAuthorized.prop="onPaymentDataAuthorized">
</google-pay-button>

<script>
    import "@google-pay/button-element";
    export default {
        ...
    }
</script>

我期待有应该显示谷歌支付按钮,但它显示警告.

推荐答案

这是一个警告.然而,该元素仍然需要生成.错误的原因是@google-pay/button-element不是Vue组件,但他们正在寻找名为<google-pay-button>的元素来显示按钮.

Vue.js旨在帮助开发,因此它表明<google-pay-button>是一个未声明的组件,确认您是否打算以这种方式使用它.这些特殊命名的元素可以放在例外列表中.我将演示如何使用Vite.

import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";

const customElements = ['google-pay-button'];

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue({
      template: {
        compilerOptions: {
          // consider any tag with a dash as a custom element
          isCustomElement: (tag) => customElements.includes(tag), // can write any condition here, the key is to cover all your custom components, even if it's as simple as tag.startsWith("google-pay-") or any other
        },
      },
    }),
  ],
});

更多信息

Vue.js相关问答推荐

虚拟DOM在Vue中姗姗来迟

使用V-TOOLTIP(实例化)使工具提示在V-文本字段中显示清晰的图标

为什么在 Vue2 中调用 this.$emit() 后 props 没有立即更新?

我需要在 nuxt2 上使用 /index 作为 url 的一部分

v-model 修饰符返回空

我可以在打印 HTML 页面时使用作用域 CSS 吗? (使用 Laravel 和 Vue.js)

在组件之间共享 websocket 连接

在 Vue 文件中创建根 Vue 实例

Vuetify Datatable - 在所有列上启用内容编辑

如何在 vue.js 2 的其他组件中调用方法?

将自定义部分添加到 v-autocomplete 下拉列表

VueJS + Typescript:类型上不存在属性

如何将 mapActions 与 vue + Typescript 类组件一起使用?

vuejs中通过变量动态调用方法

SVG 加载 vue-svg-loader; [Vue 警告]:无效的组件定义

如何克隆props对象并使其无react

为 Vue 组件动态添加属性

基本 vue.js 2 和 vue-resource http 获取变量赋值

所有 vue props和数据都给出错误 Property属性在 type 上不存在,带有 typescript

使用 Vee-validate 禁用按钮,直到正确填写表单