【发布时间】:2018-05-18 17:48:38
【问题描述】:
在我的 vue2 应用程序中,我有一个包含多个子组件的父组件。一个这样的子组件(我将其称为 PaymentComponent)是一个用于捕获支付信息的简单对话框。
目前,应用程序中有几个地方可以显示支付对话框。但是,我无法理解如何使用其他子组件中的按钮在 PaymentComponent 中显示对话框。
下面是支付组件。关于如何使用共享相同父组件的另一个组件中的按钮来显示对话框的任何提示?
<template>
<v-dialog v-model="paymentDialog" max-width="500">
<card
class='stripe-card'
:class='{ complete }'
stripe='pk_test_xxxxxxxxxxxxxxxxxxxx'
:options='stripeOptions'
@change='complete = $event.complete'>
</card>
<v-spacer></v-spacer>
<v-btn color="green darken-1" flat="flat" @click.native="paymentDialog = false">Disagree</v-btn>
<v-btn color="green darken-1" flat="flat" class="pay-with-stripe" @click='pay' :disabled='!complete'>Agree</v-btn>
</v-dialog>
</template>
<script>
// import { stripeKey, stripeOptions } from './stripeConfig.json'
import { Card, createToken } from 'vue-stripe-elements-plus'
export default {
name: 'stripe-payment',
data () {
return {
complete: false,
stripeOptions: {
// see https://stripe.com/docs/stripe.js#element-options for details
},
stripeKey: '',
paymentDialog: false
}
},
components: { Card },
methods: {
pay () {
// createToken returns a Promise which resolves in a result object with
// either a token or an error key.
// See https://stripe.com/docs/api#tokens for the token object.
// See https://stripe.com/docs/api#errors for the error object.
// More general https://stripe.com/docs/stripe.js#stripe-create-token.
createToken().then(data => console.log(data.token))
}
}
}
</script>
【问题讨论】:
-
请显示
v-dialog组件
标签: javascript vue.js vuejs2