标签:web 令行 gui 获取数据 off 文档 需要 执行方法 temp
搭建vue的开发环境:
https://cn.vuejs.org/v2/guide/installation.html
1、必须要安装nodejs
2、搭建vue的开发环境 ,安装vue的脚手架工具 官方命令行工具
npm install --global vue-cli / cnpm install --global vue-cli (此命令只需要执行一次)
3、创建项目 必须cd到对应的一个项目里面
vue init webpack vue-demo01
cd vue-demo01
cnpm install / npm install 如果创建项目的时候没有报错,这一步可以省略。如果报错了 cd到项目里面运行 cnpm install / npm install
npm run dev
4、另一种创建项目的方式 (推荐) ***
vue init webpack-simple vuedemo02
cd vuedemo02
cnpm install / npm install
npm run dev
cnpm 下载包的速度更快一些。
地址:http://npm.taobao.org/
安装cnpm:
npm install -g cnpm --registry=https://registry.npm.taobao.org
官方文档:https://router.vuejs.org/zh/
vue路由配置:
1.安装
npm install vue-router --save / cnpm install vue-router --save
2、引入并 Vue.use(VueRouter) (main.js)
import VueRouter from ‘vue-router‘
Vue.use(VueRouter)
3、配置路由
1、创建组件 引入组件
2、定义路由 (建议复制s)
const routes = [
{ path: ‘/foo‘, component: Foo },
{ path: ‘/bar‘, component: Bar },
{ path: ‘*‘, redirect: ‘/home‘ } /*默认跳转路由*/
]
3、实例化VueRouter
const router = new VueRouter({
routes // (缩写)相当于 routes: routes
})
4、挂载
new Vue({
el: ‘#app‘,
router,
render: h => h(App)
})
5 、根组件的模板里面放上这句话 即在App.vue里放 <router-view></router-view>
6、路由跳转
<router-link to="/foo">Go to Foo</router-link>
<router-link to="/bar">Go to Bar</router-link>
注:跟组件模板
动态路由写法
<router-link :to="‘/content/‘+key">{{key}}--{{item}}</router-link>
获取动态路由的值
console.log(this.$route.params); /*获取动态路由传值*/
1.2 Get传值和获取值
Get 传值的写法
<router-link :to="‘/pcontent?id=‘+key">{{key}}--{{item}}</router-link>
获取值
mounted(){
//获取get传值
console.log(this.$route.query);
}
编程式的导航,是利用JavaScript跳转路由。
设置此 界面上的页面路径会产生变化
const router = new VueRouter({
mode: ‘history‘, /*hash模式改为history*/
routes // (缩写)相当于 routes: routes
})
标签:web 令行 gui 获取数据 off 文档 需要 执行方法 temp
原文地址:https://www.cnblogs.com/fist/p/12601128.html