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

380
Visualizações
Pass value in vuejs?

In detail.vue :

data() {
    return {
      columns: [
        {
          label: "name",
          field: "name",
        },
        {
          label: "status",
          field: "status",
        },
      row: [],
    };
  },
  // call Api
  created() {
    axios
      .get("/detail")
      .then((res) => {
        this.rows = res.data;
      })
      .catch((error) => {
        console.log(error);
      });
  },
  methods: {
    detailFilter: function (name, status) {
        console.log(name, status)
      },
  },

template :

<filter-list
      v-on:detail-filter="detailFilter"
    />

In Filter.vue

data() {
    return {
      name: '',
      status: '',
      options: [
         { label: 'Success', value: 'pending' },
         { label: 'Fail', value: 'active' },
      ],
    };
  },
  methods: {
    changeDetailFilter: function () {
  this.$emit(
    "detail-filter",
    this.name,
    this.status,
  );
  localStorage.setItem('name', this.name);
  localStorage.setItem('status', JSON.stringify(this.status))
  },

template:

          <b-col md="3">
            <b-form-group>
              <label>Name:</label>
              <b-form-input
                type="text"
                v-model="name"
                v-on:change="changeDetailFilter()"
              />
            </b-form-group>
          </b-col>
          <b-col md="3">
            <label>status:</label>
            <v-select
              :options="options"
              v-model="status"
              @input="changeDetailFilter()"
            />
          </b-col>

Now I want to check created () with name and status, then pass in params for it. for example:

created() {
    axios
      .get("/detail",{
        params: {
         name: name,
         status: status
        },
      })
      .then((res) => {
        this.rows = res.data;
      })
      .catch((error) => {
        console.log(error);
      });
  },

Is there a way to get the name, and status passed to created(), using localStorage.getItem('name'); give me ideas.Thanks

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

@good perhaps something like this

created() {
  let name = localStorage.getItem('name')
  let status = localStorage.getItem('status')
  // or if what you're fetching from localStorage is
  // an Object,
  // let someObject = JSON.parse(localStorage.getItem('someObject')).
  // then name could be someObject.name and status someObject.status
  
  axios
    .get("/detail",{
      params: {
        name: name,
        status: status
      },
    })
    .then((res) => {
      this.rows = res.data;
    })
    .catch((error) => {
      console.log(error);
    });
},
over 4 years ago · Santiago Trujillo Relatório
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