K
K
Kaymakov2021-05-21 11:08:50
Vue.js
Kaymakov, 2021-05-21 11:08:50

Why doesn't vue store the object in an array?

Started learning vue yesterday.
I want to make sure that when entering a word, the name is saved in the array and after displaying it as a card, where the new value is located.
Here is the code

data() {
    return {
      ticker: "default",
      tickers: [
        {name: 'Demonstration', price: "5500"},
        {name: 'Demonstration1', price: "6500"},
        {name: 'Demonstration2', price: "7500"},],
    };
  },
  methods: {
    addTicker() {
      const newTicker = {name:this.ticker, price: '8500'}
      this.tickers.push(newTicker);
    },
  },

Everything is done, only the card appears and immediately disappears, as I understand it, vue saved the entered data, displayed it and then deleted it. Why this happens, I don't understand.
Explain, please.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WapSter, 2021-05-21
@Kaymakov

In this way, the element is easily added to the array. Look for the error elsewhere. I can swange that you have addTicker hanging on a link or on a button in the form and the default action occurs.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question