Vue: Allow using js constants in template event attributes.

Created on 28 Dec 2017  ·  4Comments  ·  Source: vuejs/vue

What problem does this feature solve?

Remove redundant values between actions names and template attributes events.

I often use the same values for actions names and component event methods, so this will allow simplicity.

What does the proposed API look like?

Make the following code valid.
Currently it's impossible to reference On.UPDATE_SEARCH_TERM from @input.
A valid code will clone the constant value in the template instead of reference it.

<template>
    <v-text-field @input="On.UPDATE_SEARCH_TERM"/>
</template>

<script>
    import {mapActions} from 'vuex';
    import * as On from "../store/actionKeys";

    export default {
        name: 'minimal-exemple',
        methods: {
            ...mapActions([On.UPDATE_SEARCH_TERM])
        }
    }

</script>

Most helpful comment

So I use this now:

<template>
        <v-text-field @input="termInputChanged" />
</template>

<script>
    import {mapActions} from 'vuex';
    import {On} from "../store/keys";

    export default {
        name: 'minimal-test',
        methods: {
            ...mapActions({
                'termInputChanged': On.UPDATE_SEARCH_TERM
            })
        }
    }
</script>

All 4 comments

created () {
  this.On = On
}

Assuming On was available in the template, the result of your code would be:

<v-text-field @input=" 'someString' "/>

Which of course is not a valid callback function - it's a string. So making constants avaliable in templates whatever way won't solve your problem.

Thanks you both

So I use this now:

<template>
        <v-text-field @input="termInputChanged" />
</template>

<script>
    import {mapActions} from 'vuex';
    import {On} from "../store/keys";

    export default {
        name: 'minimal-test',
        methods: {
            ...mapActions({
                'termInputChanged': On.UPDATE_SEARCH_TERM
            })
        }
    }
</script>
Was this page helpful?
0 / 5 - 0 ratings

Related issues

gkiely picture gkiely  ·  3Comments

robertleeplummerjr picture robertleeplummerjr  ·  3Comments

guan6 picture guan6  ·  3Comments

6pm picture 6pm  ·  3Comments

aviggngyv picture aviggngyv  ·  3Comments