自定义组件
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>test</title> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> <script src="https://unpkg.com/axios/dist/axios.min.js"></script> </head> <body> <div id="myspan"> <ul> <component-li v-for="li in lists" v-bind:item="li"></component-li> </ul> </div> </body> <script> Vue.component("component-li",{ props:["item"], template:"<li>{{item}}</li>" }) var vue = new Vue({ el:"#myspan", data:{ lists:[] }, mounted() { axios.get("data.json") .then(response=>this.lists=response.data) } }) </script> </html>