在components中写vue文件,在assets中放css,js,static静态文件
使用路由:
#安装:cd先进入工程目录
npm install vue-router #要打对,他的有一个类似包很容易打错
#main.js导入路由
import VueRouter from 'vue-router'
Vue.use(VueRouter)
#在components中新建Index.vue文件
#在main.js中:
#导入组件
import Index from "./components/Index.vue"
#定义路由规则
var routes = [
{
path:"/", #根路径
redirect:'/Index' #重定向
},
{
path:"/index",
component:Index
},
]
#创建路由对象
var router = new VueRouter({
routes #这里是路由规则所定义的名字
})
#挂载路由对象
new Vue({
render: h => h(App),
router #new Vue添加这一行就可以了,与创建路由对象同名
}).$mount('#app')
#在App.vue中:
<router-view></router-view> #子模板渲染位置标签
#路由内部跳转方式
<router-link to="/index">index</router-link>
使用Axios的ajax时配置:
#main.js中
#这里使用Axios,去替代ajax
#1.安装和导入 npm install --save axios
#2.导入Axios
import Axios from 'axios'
Vue.prototype.$ajax = Axios #利用Vue原型对象给vue对象添加了共享属性,这使得Axios和原ajax没什么区别