Npm introduced using uuid installed modules and module - VUE

<template>
  <div>
      <form @submit.prevent="addTodo">
        <Input v-model = "title" type = "text" name = "title" placeholder = "Please add a to-do ...">
        <input type="submit" value="添加" class="btn">
      </form>
  </div>
</template>

 

<script>
/ * * Module incorporated npm /
import uuid from 'uuid'
export default {
   name:'AddTodos',
   data() {
       return {
           title:'',
       }
   },
   methods: {
       addTodo(){
           const newTodo = {
               id: uuid.v4(),
               title:this.title,
               completed:false
           }
           console.log(newTodo);
           / * Register events, triggered by the parent * /
           this.$emit('handleAdd', newTodo)
           this.title = ''
       }
   },
}

</script>

 

 

Guess you like

Origin www.cnblogs.com/500m/p/11780506.html