search

Home  >  Q&A  >  body text

javascript - How to make a custom function automatically execute when loading in vuejs

For example, if a method is defined in a component:

export default {
  methods: {
    changeIcon () {}
  }
}

How to make the changeIcon function execute automatically?

PHP中文网PHP中文网2832 days ago769

reply all(2)I'll reply

  • ringa_lee

    ringa_lee2017-05-19 10:43:14

    export default {
        //这里可以用created或mounted
        mounted() {
            this.changeIcon()
        },
        methods: {
            changeIcon () {}
        }
    }

    reply
    0
  • phpcn_u1582

    phpcn_u15822017-05-19 10:43:14

    Just call it once in the vue life cycle beforeCreate or Create!
    Attached is also a vue life cycle example.

    reply
    0
  • Cancelreply