Vue to pass different values to the component

Source: Internet
Author: User

Here is an example of the Vue official website, vue to pass data traversal to multiple components, which is what we often do in actual development. Generally large applications are built using components, we need to pass different values to the components to achieve different display, to achieve the reuse of code.

<! DOCTYPE html>  
Code Analysis: 

Here I use a Vue CDN directly, and then instantiate the Vue object to use. Create a Vue instance

    var app7 = new Vue ({
        el: ' #app ',
        data: {
            grocerylist: [
                {id:0, text: ' Vegetable '},
                {id:1, text: ' Cheese '},< c7/>{id:2, text: ' Anything other people eat '}}}
    
Create a Vue component globally
    Vue.component (' Todo-item ', {
        props: [' todo '],
        Template: ' <li>{{todo.text}}</li> '
    })
Assign a different value to a component through a Vue instance (bind the value to a variable via bind, and the subassembly accepts the variable value passed through props)
    <div id= "App" >
        <ol>
            <!--Now we provide the Todo object for each Todo-item Todo object is a variable, that is, its contents can be dynamic. We also need to provide a "key" for each component. -->
            <todo-item v-for= "item in Grocerylist" v-bind:todo= "item" v-bind:key= "Item.id" ></todo-item>
        </ol>
    </div>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.