[TOC]
#### 1.定义一下单页面路由
注意:需要引入 Vue-roter.js
<div id="hdcms">
<router-link to="/hdphp">HDPHP</router-link>
<router-link to="/hdcms">HDCMS</router-link>
<router-view></router-view>
</div>
<script>
const hdphp={
template:'<h1>hdphp</h1>'
}
const hdcms={
template:'<h1>hdcms</h1>'
}
let routes=[
{path:'/hdphp',component:hdphp},
{path:'/hdcms',component:hdcms},
];
//要把组件交给路由器
let router = new VueRouter({routes:routes});
new Vue({
el: '#hdcms',
router:router
});
</script>
#### 2.vue-router之路由参数的随意设置与伪静态链接地址处理
注意:需要引入 Vue-roter.js
<div id="hdcms">
<router-link to="/content">内容 </router-link>
<router-view></router-view>
</div>
<script type="text/x-template" id="content">
<div>
cid:{{$route.params.cid}} - id:{{$route.params.id}}
<br>
<button @click="show">检测参数</button>
</div>
</script>
<script>
const content={
template:'#content',
methods:{
show(){
console.log(this.$route.params);
}
}
}
let routes=[
{path:'/content-:cid-show-:id.html',component:content},
];
//要把组件交给路由器
let router = new VueRouter({routes});
new Vue({
el: '#hdcms',
router
});
</script>
#### 3.vue-router之路由参数的验证处理保存路由安全
注意:需要引入 Vue-roter.js
<div id="hdcms">
<router-link to="/content">内容 </router-link>
<router-view></router-view>
</div>
<script type="text/x-template" id="content">
<div>
id:{{$route.params.id}}
<br>
<button @click="show">检测参数</button>
</div>
</script>
<script>
const content={
template:'#content',
methods:{
show(){
console.log(this.$route.params);
}
}
}
let routes=[
{path:'/content/:id(\\d{2})',component:content},
];
//要把组件交给路由器
let router = new VueRouter({routes});
new Vue({
el: '#hdcms',
router
});
</script>
#### 4.vue-router之路由参数默认值的设置技巧
注意:需要引入 Vue-roter.js
<div id="hdcms">
<router-link to="/content">内容</router-link>
<router-view></router-view>
</div>
<script type="text/x-template" id="content">
<div>
id:{{id}}
<button @click="show">检测参数</button>
</div>
</script>
<script>
const content = {
template: '#content',
data(){
return {
id: 0
}
},
mounted(){
this.id = this.$route.params.id;
if (!this.id) {
this.id = 1;
}
},
methods: {
show(){
console.log(this.$route.params);
}
}
}
let routes = [
{path: '/content/:id?', component: content},
];
//要把组件交给路由器
let router = new VueRouter({routes});
new Vue({
el: '#hdcms',
router
});
</script>
#### 5.vue-router之实例操作新闻列表单页面应用与路由别名的使用
注意:需要引入 Vue-roter.js
<div id="hdcms">
<router-view></router-view>
</div>
<script type="text/x-template" id="home">
<div>
<li v-for="v in news">
<router-link :to="{name:'content',params:{id:v.id}}">{{v.title}}</router-link>
</li>
</div>
</script>
<script type="text/x-template" id="content">
<div>
<h1>{{field.title}}-{{field.id}}</h1>
<p>
{{field.content}}
</p>
<router-link to="/">返回首页</router-link>
</div>
</script>
<script>
var data = [
{id:1,title:'HDPHP开源免费框架',content:'这是内容....'},
{id:2,title:'HDCMS内容管理系统',content:'这是HDCMS内容....'}
];
const home = {
template: '#home',
data(){
return {
news:data
}
}
}
const content = {
template: '#content',
data(){
return {
field:{}
}
},
mounted(){
var id =this.$route.params.id;
for(let k=0;k<data.length;k++){
if(data[k].id==id){
this.field = data[k];
}
}
}
}
let routes = [
{path: '/', component: home},
{path: '/content/:id', component: content,name:'content'},
];
//要把组件交给路由器
let router = new VueRouter({routes});
new Vue({
el: '#hdcms',
router
});
</script>
#### 6.Vue-router之路由嵌套在文章系统中的使用方法
注意:需要引入 Vue-roter.js
<div id="hdcms">
<router-view></router-view>
</div>
<script type="text/x-template" id="home">
<div>
<li v-for="v in news">
<router-link :to="{name:'content',params:{id:v.id}}">{{v.title}}</router-link>
</li>
<router-view></router-view>
</div>
</script>
<script type="text/x-template" id="content">
<div>
<h1>{{field.title}}-{{field.id}}</h1>
<p>
{{field.content}}
</p>
<router-link to="/">返回首页</router-link>
</div>
</script>
<script>
var data = [
{id:1,title:'HDPHP开源免费框架',content:'这是内容....'},
{id:2,title:'HDCMS内容管理系统',content:'这是HDCMS内容....'}
];
const home = {
template: '#home',
data(){
return {
news:data
}
}
}
const content = {
template: '#content',
data(){
return {
field:{}
}
},
mounted(){
var id =this.$route.params.id;
for(let k=0;k<data.length;k++){
if(data[k].id==id){
this.field = data[k];
}
}
}
}
let routes = [
{path: '/', component: home,children:[
{path: '/content/:id', component: content,name:'content'},
]},
];
//要把组件交给路由器
let router = new VueRouter({routes});
new Vue({
el: '#hdcms',
router
});
</script>
#### 7.Vue-router之使用watch与mounted解决同一组件页面不刷新数据的问题
<div id="hdcms">
<router-view></router-view>
</div>
<script type="text/x-template" id="home">
<div>
<li v-for="v in news">
<router-link :to="{name:'content',params:{id:v.id}}">{{v.title}}</router-link>
</li>
<router-view></router-view>
</div>
</script>
<script type="text/x-template" id="content">
<div>
<h1>{{field.title}}-{{field.id}}</h1>
<p>
{{field.content}}
</p>
<router-link to="/">返回首页</router-link>
</div>
</script>
<script>
var data = [
{id:1,title:'HDPHP开源免费框架',content:'这是内容....'},
{id:2,title:'HDCMS内容管理系统',content:'这是HDCMS内容....'}
];
const home = {
template: '#home',
data(){
return {
news:data
}
}
}
const content = {
template: '#content',
data(){
return {
field:{}
}
},
watch:{
'$route'(to,from){
this.load();
}
},
mounted(){
this.load();
},
methods:{
load(){
var id =this.$route.params.id;
for(let k=0;k<data.length;k++){
if(data[k].id==id){
this.field = data[k];
}
}
}
}
}
let routes = [
{path: '/', component: home,children:[
{path: '/content/:id', component: content,name:'content'},
]},
];
//要把组件交给路由器
let router = new VueRouter({routes});
new Vue({
el: '#hdcms',
router
});
</script>
#### 8.vue-router之通过程序控制路由跳转
<div id="hdcms">
<router-view></router-view>
</div>
<script type="text/x-template" id="home">
<div>
<li v-for="v in news">
<a href="" @click.prevent="go(v.id)">{{v.title}}</a>
</li>
</div>
</script>
<script type="text/x-template" id="content">
<div>
<h1>{{field.title}}-{{field.id}}</h1>
<p>
{{field.content}}
</p>
<a href="" @click.prevent="back()">返回</a>
</div>
</script>
<script>
var data = [
{id:1,title:'HDPHP开源免费框架',content:'这是内容....'},
{id:2,title:'HDCMS内容管理系统',content:'这是HDCMS内容....'}
];
const home = {
template: '#home',
data(){
return {
news:data
}
},
methods:{
go(id){
//写业务逻辑
// var url = '/content/'+id;
//{name:'content',params:{id:id}}
var url ={path:'/content/'+id}
this.$router.push(url);
}
}
}
const content = {
template: '#content',
data(){
return {
field:{}
}
},
watch:{
'$route'(to,from){
this.load();
}
},
mounted(){
this.load();
},
methods:{
load(){
var id =this.$route.params.id;
for(let k=0;k<data.length;k++){
if(data[k].id==id){
this.field = data[k];
}
}
},
back(){
this.$router.go(-1);
}
}
}
let routes = [
{path: '/', component: home},
{path: '/content/:id', component: content,name:'content'}
];
//要把组件交给路由器
let router = new VueRouter({routes});
new Vue({
el: '#hdcms',
router
});
</script>
#### 9.vue-router之命名视图的实例讲解
<style>
.menu{border:solid 2px #999;padding:10px;display: block;}
.news{float:left;border:solid 1px red;padding:20px;width:300px;}
.slide{float:left;border:solid 1px red;padding:20px;width:300px;}
</style>
<div id="hdcms">
<router-view class="menu"></router-view>
<router-view class="news" name="news"></router-view>
<router-view class="slide" name="slide"></router-view>
</div>
<script type="text/x-template" id="menu">
<div>
<a href="http://houdunren.com">后盾人</a>
<a href="http://www.houdunwang.com">后盾IT教育</a>
</div>
</script>
<script type="text/x-template" id="news">
<div>
<li v-for="v in news">{{v.title}}</li>
</div>
</script>
<script type="text/x-template" id="slide">
<div>
<li v-for="v in data">{{v.title}}</li>
</div>
</script>
<script>
const menu = {
template: '#menu',
}
const news = {
template: '#news',
data(){
return {
news:[
{title:'houdunren.com'},
{title:'hdphp.com'},
]
}
}
}
const slide = {
template: '#slide',
data(){
return {
data:[
{title:'后盾人'},
{title:'后盾PHP培训'},
]
}
}
}
let routes = [
{
path: '/', components: {
default: menu,
news: news,
slide: slide
}
},
];
//要把组件交给路由器
let router = new VueRouter({routes});
new Vue({
el: '#hdcms',
router
});
</script>
#### 10.vue-router之重定向redirect的使用技巧
<div id="hdcms">
<router-link to="/">首页</router-link>
<a href="http://www.houdunwang.com">后盾人</a>
<router-link to="/about">关于我们</router-link>
<router-view></router-view>
</div>
<script type="text/x-template" id="home">
<div>
<li v-for="v in news">
<a href="" @click.prevent="go(v.id)">{{v.title}}</a>
</li>
</div>
</script>
<script type="text/x-template" id="content">
<div>
<h1>{{field.title}}-{{field.id}}</h1>
<p>
{{field.content}}
</p>
<a href="" @click.prevent="back()">返回</a>
</div>
</script>
<script>
var data = [
{id:1,title:'HDPHP开源免费框架',content:'这是内容....'},
{id:2,title:'HDCMS内容管理系统',content:'这是HDCMS内容....'},
{id:3,title:'关于我们',content:'一个认真录制视频教程的有激情的团队!!!!'}
];
const home = {
template: '#home',
data(){
return {
news:data
}
},
methods:{
go(id){
//写业务逻辑
// var url = '/content/'+id;
//{name:'content',params:{id:id}}
var url ={path:'/content/'+id}
this.$router.push(url);
}
}
}
const content = {
template: '#content',
data(){
return {
field:{}
}
},
watch:{
'$route'(to,from){
this.load();
}
},
mounted(){
this.load();
},
methods:{
load(){
var id =this.$route.params.id;
for(let k=0;k<data.length;k++){
if(data[k].id==id){
this.field = data[k];
}
}
},
back(){
this.$router.go(-1);
}
}
}
let routes = [
{path: '/', component: home},
{path: '/content/:id', component: content,name:'content'},
{path: '/about', redirect:{name:'content',params:{id:3}}}
];
//要把组件交给路由器
let router = new VueRouter({routes});
new Vue({
el: '#hdcms',
router
});
</script>
#### 11.vue-router之使用路由别名定制URL
<div id="hdcms">
<router-link to="/">首页</router-link>
<a href="http://www.houdunwang.com">后盾人</a>
<router-link to="/about">关于我们</router-link>
<router-view></router-view>
</div>
<script type="text/x-template" id="home">
<div>
<li v-for="v in news">
<a href="" @click.prevent="go(v.id)">{{v.title}}</a>
</li>
</div>
</script>
<script type="text/x-template" id="content">
<div>
<h1>{{field.title}}-{{field.id}}</h1>
<p>
{{field.content}}
</p>
<a href="" @click.prevent="back()">返回</a>
</div>
</script>
<script>
var data = [
{id:1,title:'HDPHP开源免费框架',content:'这是内容....'},
{id:2,title:'HDCMS内容管理系统',content:'这是HDCMS内容....'},
{id:3,title:'关于我们',content:'一个认真录制视频教程的有激情的团队!!!!'}
];
const home = {
template: '#home',
data(){
return {
news:data
}
},
methods:{
go(id){
//写业务逻辑
// var url = '/content/'+id;
//{name:'content',params:{id:id}}
var url ={path:'/content/'+id}
this.$router.push(url);
}
}
}
const content = {
template: '#content',
data(){
return {
field:{}
}
},
watch:{
'$route'(to,from){
this.load();
}
},
mounted(){
this.load();
},
methods:{
load(){
var id =this.$route.params.id;
for(let k=0;k<data.length;k++){
if(data[k].id==id){
this.field = data[k];
}
}
},
back(){
this.$router.go(-1);
}
}
}
let routes = [
{path: '/', component: home},
{path: '/content/:id', component: content,name:'content'},
{path: '/content/3', alias:['/about']},
{path: '/content/2', alias:['/hdphp']}
];
//要把组件交给路由器
let router = new VueRouter({routes});
new Vue({
el: '#hdcms',
router
});
</script>
#### 12.vue-router之使用html5history模式去除hash锚点生成优雅的url
1.创建..htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [L]
<div id="hdcms">
<router-view></router-view>
</div>
<script type="text/x-template" id="home">
<div>
<li v-for="v in news">
<a href="" @click.prevent="go(v.id)">{{v.title}}</a>
</li>
</div>
</script>
<script type="text/x-template" id="content">
<div>
<h1>{{field.title}}-{{field.id}}</h1>
<p>
{{field.content}}
</p>
<a href="" @click.prevent="back()">返回</a>
</div>
</script>
<script>
var data = [
{id:1,title:'HDPHP开源免费框架',content:'这是内容....'},
{id:2,title:'HDCMS内容管理系统',content:'这是HDCMS内容....'}
];
const home = {
template: '#home',
data(){
return {
news:data
}
},
methods:{
go(id){
//写业务逻辑
// var url = '/content/'+id;
//{name:'content',params:{id:id}}
var url ={path:'/content/'+id+'.html'}
this.$router.push(url);
}
}
}
const NotFound = {
template: '<h1>你请求的页面不存在</h1>',
}
const content = {
template: '#content',
data(){
return {
field:{}
}
},
watch:{
'$route'(to,from){
this.load();
}
},
mounted(){
this.load();
},
methods:{
load(){
var id =this.$route.params.id;
for(let k=0;k<data.length;k++){
if(data[k].id==id){
this.field = data[k];
}
}
},
back(){
this.$router.go(-1);
}
}
}
let routes = [
{path: '/', component: home},
{path: '/content/:id.html', component: content,name:'content'},
{path: '*', component: NotFound},
];
//要把组件交给路由器
let router = new VueRouter({
mode:'history',
routes
});
new Vue({
el: '#hdcms',
router
});
</script>
- html&jquery网页特效
- 标签分类及特点
- 关于文字标签
- 网页定时跳转
- css透明度和插件
- 0.前端常用工具
- 1.tab切换效果
- 2.tab切换效果多个代码复用
- 3.百度新闻导航条效果
- 4.解决鼠标移入过快的问题
- 5.滚动条位置
- 6.元素尺寸
- 7.全选反选操作
- 8.固定定位
- 9.开关效果
- 10.节点操作
- 11.仿小米商品展示效果
- 12.仿小米商品展示效果复用
- 13.固定导航栏效果
- 14.凡客轮播图效果
- 15.顶部下滑广告效果
- 16.京东左右滑动轮播图
- 17.京东左右滑动无缝轮播图
- 18.选择器
- 19.筛选
- 20.开关效果
- 21.滑动效果
- 22.小米商品效果css实现
- 23.元素水平垂直居中
- laravel5.6
- LARAVEL 介绍&安装
- javascript & css 脚手架
- php常用工具类
- 安装laravel-ide-helper增强代码提示
- 使用migration创建表和数据填充
- 解决mysql5.7以下laravel不能执行数据迁移的问题
- 路由
- 登陆操作自定义模型
- 使用中间件middleware进行登录权限验证
- 进行表单验证处理
- 使用laracasts-flash定制消息提示
- 资源路由
- 宝塔面板安装fileinfo扩展
- laravel上传处理与使用hdjs快速实现前端上传组件
- thinkphp
- phpstorm
- phpstorm安装插件
- 定义快捷键
- 关闭提示
- 将代码实时同步到远程服务器
- sublime
- composer
- git使用
- git安装和配置作者信息
- git新建项目和维护项目
- git日志操作
- git别名操作
- git分支操作
- git生成发布压缩包
- git系统别名
- gitrebase操作
- 使用SSH与GITHUB远程服务器进行无密码连接
- 本地版本库主动使用remote与远程GITHUB进行关联
- 本地分支与GITHUB远程分支同步
- 项目实战-新入职员工参与项目开发时分支使用
- 自动部署
- ios开发
- linux
- 1.centos6.5 mysql忘记登入密码
- html5
- 标签
- 表单
- 音频与视频
- webstorage储存
- canvas
- css3
- 01.CSS3布局
- 02.transition动画
- 03.animation动画
- 04.flex弹性盒模型
- Less
- gulpjs
- es6
- ES6模块化
- let和const命令
- ES6函数扩展&解构赋值
- JavaScript之数据遍历
- class类
- Set和Map数据结构
- Vue
- 1.创建第一个应用
- 2.属性动态绑定
- 3.表达式
- 4.解决phpstorm不识别ECMASCRIPT6语法的问题
- 5.watch监听属性
- 6.使用object与array控制class
- 7.条件渲染
- 8.循环
- 9.变异方法
- 10.事件
- 11.表单
- 12.组件
- 13.css过渡动
- 14.js库控制vue过渡动作
- 15.自定义指令directive
- 16.使用vue-cli初始化单页面应用
- 17.Vue-router路由
- 18.vuex
- 19.vue-cli
- webpack
- zanui
- nodejs