项目是用vue-cli生成的,然后在webstrom打开
index.html
<!DOCTYPE html> <html lang="en"> <head> <base href="src/assets/"> <meta charset="utf-8"> <title>fuqing_studio</title> </head> <body> <div id="app"></div> <script src="/dist/build.js"></script> <style> @import "css/base.css"; @import "css/patient_education.css"; @import "css/swiper.min.css"; @import "css/mine.css"; </style> </body> </html>
main.js
import Vue from 'vue' import VueRouter from 'vue-router' import Index from './component/indexTop.vue' new Vue({ render: h => h(Index), }).$mount('#app')
我希望进去的页面是首页顶部的轮播图
<template> <div id="indexTop"> <div class="swiper-container"> <div class="swiper-wrapper"> <div v-for="item in banners" @click="jumpUrl($index)" class="swiper-slide img"><img src="{{item.path}}" alt=""></div> </div> <div class="swiper-pagination"></div> </div> </div> </template> <script> import Vue from 'vue' import axios from 'axios' Vue.prototype.$http = axios new Vue({ data:{ banners:{ }, }, methods: { jumpUrl: function(index){ } }, mounted: function () { this.$nextTick(function () { var self = this; axios.get('http://localhost:66/studio/banner') .then(function(res){ console.log(res.data); self.banners = res.data }) .catch(function(err){ console.log(err); }) }); } }).$mount('#indexTop') </script>
然后就报错了,改了好半天都不行
说得这么清楚了,你英语是语文老师教的?
src={{item.path}}改成 :src="item.path"
还有既然是vue-cli,那就只需要main.js里面的那个vue实例就行了,其他的都是组件,怎么访问组件,就得使用vue-router了。你这存在两个vue实例了。