Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

149
Visualizações
Workarounds to using this in Vue

I am attempting to create a PayPal checkout order on my Vue site. I am currently passing two props to the component as well as two data objects

  props: {
    price: Number,
    shipping: Number,
  },
  data() {
    return {quantity: 1, switches: 'red'}
  },

I am referencing these four variables in my code as this.price, this.shipping etc. I have confirmed these are all valid

I am attempting to access these inside a method but this is being over-ridden and all four of these are undefined.

I still don't quite understand this, but I was under the impression that using an arrow function as I have done should stop this from changing. Is this not the case?

Code

   await paypal.Buttons({
      style: {
        layout: 'vertical',
        color: 'black',
        shape: 'pill',
      },
      createOrder: (data, actions) => {
        return actions.order.create({
          purchase_units: [{
            amount: {
              currency_code: "USD",
              value: ((this.price + this.shipping) * this.quantity).toString(),
              breakdown: {
                item_total: {  /* Required when including the `items` array */
                  currency_code: "USD",
                  value: this.price.toString()
                },
                shipping: {
                  currency_code: "USD",
                  value: this.shipping.toString()
                }
              }
            },
            items: [
              {
                name: "First Product Name", /* Shows within upper-right dropdown during payment approval */
                description: "Optional descriptive text..", /* Item details will also be in the completed paypal.com transaction view */
                unit_amount: {
                  currency_code: "USD",
                  value: this.price.toString()
                },
                quantity: this.quantity.toString
              },
            ]
          }]
        });
      },
    }).render('#paypal-button-container')
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda