Skip to content

Instantly share code, notes, and snippets.

@luc0
Last active February 7, 2022 14:45
Show Gist options
  • Save luc0/8b9a75fe9a6f8c1f78a4a35497316959 to your computer and use it in GitHub Desktop.
Save luc0/8b9a75fe9a6f8c1f78a4a35497316959 to your computer and use it in GitHub Desktop.

VUE

Mas usado: props, data, computed. methods, mounted

Components:

componentes que tenga dentro. (para no escribir c/u ver https://youtu.be/7YZ5DwlLSt8?t=1273)

Props

Data

Computed

datos calculados. (es como un data, pero cachea si puede) para usar store:

computed: {
  ...mapState( [ 'laHora' ] )
}

Mounted

cuando es visible en el dom

Methods

para usar store:

methods: {
  ...mapActions( [ 'actualizaHora' ] )
}

STORE (VUEX)

State

Getters

son computers del store

doneTodos: state => {
  return state.todos.filter(todo => todo.done)
}

Actions

llama a la mutation

increment (context) {
  context.commit('increment')
}

Mutations

son como events (setters)

increment (state, n) {
  state.count += n
}

Basic component

<script>
  import { defineComponent, ref, computed, reactive } from 'vue';

  export default defineComponent({
      components: { LineChart, FilterRange, FilterCoin },
      props: {
          prices: Array,
      },
      setup(props) {
          const state = reactive({
              currentRange: '1y',
          });

          const chartData = computed(() => ({
              labels: props.time
          })); // props lo pasa Inertia.

          function updateChart() {
              Inertia.post('/coin/' + state.currentCoin, {'range': state.currentRange})
          }
          return { state, chartData, updateChart };
      },
  });
</script>

Emit

$emit -> Filter.vue

<a @click="$emit('changeCoin', value)"></a>

@event -> Welcome.vue

`<Filter @changeCoin="changeCoin($event)" />`

Pasar Props

<LineChart :chartData="chartData" />

Leer Props (template)

<template>
  <input :checked="currentValue.indexOf(value) != -1" />
</template>

export default defineComponent({
    props: {
        currentValue: Array
    },
    setup() {
        return {}
    },
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment