zoukankan      html  css  js  c++  java
  • vue组件之间的引用

    1.在一个.vue的文件里去引用另一个.vue的文件,比如ul里面要放很多li,就可以把li单独成一个组件,说不准其他的.vue组件会用到,这样可以多次使用,比较方便
    <template>
    <div id="home-firstpage">
    <input type="text" v-model="inputValue">
    <button @click="handleSubmint">提交</button>
    <ul>
    <!--list指的是data里的list数组-->
    <!--添加删除功能-->
    <todo-item v-for="(item,index) of list"
    :key="index"
    :content="item"
    :index="index"
    @delete="handleDelete"
    ></todo-item>
    </ul>

    </div>
    </template>

    <script>
    //引入组件ul里面的li,li单独写成了个组件,放在todoitem.vue
    import todoitem from './todoitem'
    export default {
    components: {
    'todo-item':todoitem //todo-item标签是todoitem.vue这个组件,使用局部组件
    },
    data () {//data是个函数==data:function(){}
    return{//返回的数据
    inputValue: '',
    list:[]
    }
    },
    methods: {
    //提交input里面输入的值
    handleSubmint(){
    this.list.push(this.inputValue)//list指向data里面的list,也就是this.$data.list简写,将input的值加入到数组里面去,也就是li
    this.inputValue = ''//点击提交后清空input
    },
    //删除功能
    handleDelete(index){
    this.list.splice(index,1)
    }
    },
    /* go (event) {
    event.preventDefault()
    this.$root.currentRoute = this.href
    window.history.pushState(
    null,
    routes[this.href],
    this.href
    )
    }*/
    }
    </script>

    2.以上已经把todoitem里面的li组件引入了
    todoitem我是这么写的,就写了一个简单的删除功能
    <template>
    <li @click="handleDelete">{{content}}</li>
    </template>

    <script>
    export default {
    props:['content','index'],
    methods:{
    handleDelete(){
    this.$emit('delete',this.index)//组件通讯
    }
    }

    }
    </script>
  • 相关阅读:
    postman-3http请求
    postman-2get发送请求
    postman-1版本区别、选择
    mysql-13处理重复数据
    mysql-12序列使用
    mysql-11元数据
    mysql-10临时表、复制表
    10)global预定义变量
    9)用request方式
    8)post方式提交和简单那处理
  • 原文地址:https://www.cnblogs.com/chengyalin/p/9069359.html
Copyright © 2011-2022 走看看