\n
\n\nconst app = {\n data() {\n return {\n sites: [\n { text: 'Google' },\n { text: '' },\n { text: 'Taobao' }\n ]\n }\n }\n}\nVue.createApp(app).mount('#app')\n\n[Try it Β»](#)\n\n`v-for` also supports an optional second parameter, which is the index of the current item:\n\n## v-for Example\n\n`index` is the index value of the list item:\n\n- \n
- \n {{ site.text }}\n \n
\n
\n\nconst app = {\n data() {\n return {\n sites: [\n { text: 'Google' },\n { text: '' },\n { text: 'Taobao' }\n ]\n }\n }\n}\nVue.createApp(app).mount('#app')\n\n[Try it Β»](#)\n\nUsing `v-for` within a `` tag:\n\n## v-for\n\n- \n
- \n {{ index }} - {{ site.text }}\n \n
- {{ site.text }}
- --------------
- {{ value }}
- {{ key }} : {{ value }}
- {{ index }}. {{ key }} : {{ value }}
- {{ n }}
- {{ n }}
{{site.name}}{{site.name}}
const app = { data() { return { selOption: "", sites: [ {id:1,name:"Google"}, {id:2,name:""}, {id:3,name:"Taobao"}, ] } }, methods:{ changeVal:function(event){ this.selOption = event.target.value; alert("You selected"+this.selOption); } } } Vue.createApp(app).mount('#app') \n\n[Try it Β»](#)\n\n## Using v-for on a Component\n\nIf you haven't learned about components yet, you can skip this part.\n\nOn a custom component, you can use `v-for` just like on any regular element:\n\nHowever, no data will be automatically passed to the component because components have their own isolated scope. To pass the iteration data into the component, we need to use props:\n\nThe reason `item` is not automatically injected into the component is that it would tightly couple the component to the `v-for` operation. Explicitly defining the source of the component's data allows the component to be reused in other contexts.\n\nHere is a complete example of a simple todo list:\n\n## Example\n\nYou selected: {{selOption}}
\n \n \n \n \n \n
\n\n[Try it Β»](#)- \n \n
YouTip