vue---day03

1. Vue的生命周期

- 创建和销毁的时候可以做一些我们自己的事情

- beforeCreated
- created
- beforeMount
- mounted
- beforeUpdate
- updated
- activated
- deactivated
- beforeDestroy
- destroyed

1.1 知识点回顾

1.1.1 beforeCreated 在实例创建之前除标签外,所有的vue实例需要的数据,事件都不存在
1.1.2 created 实例被我创建之后,data和事件已经被解析到,el还没有解析到
1.1.3 beforeMount 开始找标签,数据还没被渲染,事件也没被监听
1.1.4 mounted 开始渲染数据和监听事件
1.1.5 beforeUpdate 数据已经被修改在虚拟DOM,但是还没渲染到页面上
1.1.6 updated 开始使用Diff算法,将虚拟DOM中的要修改数据应用到页面上,真实DOM中的数据也被修改了
1.1.7 beforeDestroy 所有的数据都存在
1.1.8 destroyed 所有的数据都存在(在虚拟DOM中)
1.1.9 <keep-alive></keep-alive> Vue提供的用来缓存消除的标签
- activated和deactivated取代了beforeDestroy和destroyed的执行

 

 
2. Vue的路由系统

2.1 VueRouter的实现原理
- 通过监听a的锚点值,来动态的显示页面内容

2.2 VueRouter的安装使用

2.2.1 第一步:
 1       Vue.use(VueRouter)
        2.2.2 第二步:创建router对象和每个url对应的组件
 1       let Home = {
 2                 template:``,
 3             };
 4 
 5             let Login = {
 6                 template:``,
 7             };
 8 
 9             let router = new VueRouter({
10                 routes:[
11                     {
12                         name:'home',
13                         path:'/',
14                         components:Home',
15                     },
16                     {
17                         name:'login',
18                         path:'/login',
19                         components:Login,
20                     },
21                 ]
22             });
        2.2.3 第三步:注册router对象到根实例中
1       new Vue({
2                 el:'#app',
3                 template:`<App/>`,
4                 components:{
5                     App,
6                 }
7                 router:router,
8             });
        2.2.4 第四步:
1       let App = {
2                 template:`
3                     <router-link :to='{ name: 'home' }'>首页</router-link>
4                     <router-link :to='{ name: 'login' }'>登录</router-link>
5 
6                     <router-view></router-view>
7                 `
8             }
    2.3 VueRouter之命名路由
同上
2.4 VueRouter之路由参数
- user_change/1/
- user_detail/?user_id=1
 1     let Home = {
 2             template:`
 3                 <h1>欢迎</h1>
 4             `
 5         };
 6 
 7         let UserDetail = {
 8             template:`
 9                 <h2>用户详情</h2>
10             `,
11         };
12 
13         let UserChange = {
14             template:`
15                 <h3>修改用户信息</h3>
16             `,
17         };
18 
19         let App = {
20             template:`
21                 <div>
22                     <router-link :to="{ name: 'home' }">首页</router-link>
23                     <router-link :to="{ name: 'user_detail', query: { user_id: 1 } }">用户详情</router-link>
24                     <router-link :to="{ name: 'user_change', params: { user_id: 1 } }">修改用户信息</router-link>
25                     <router-view></router-view>
26                 </div>
27             `
28         };
29 
30         let router = new VueRouter({
31             routes:[
32                 {
33                     'name':'home',
34                     'path':'/',
35                     'component':Home,
36                 },
37                 {
38                     'name':'user_detail',
39                     'path':'/user_detail',
40                     'component':UserDetail,
41                 },
42                 {
43                     'name':'user_change',
44                     'path':'/user_change/:user_id',
45                     'component':UserChange,
46                 },
47             ]
48         });
    2.5 VueRouter之路由参数的实现原理
1         this.$router.params
2         this.$router.query
    2.6 VueRouter之子路由
 1      let Home = {
 2           template: `
 3               <div>
 4                   <h1>欢迎</h1>
 5               </div>
 6               `
 7           };
 8 
 9         let Phone = {
10             template: `
11                 <div>
12                     <h2>手机品牌</h2>
13                     <router-link :to="{name: 'huawei'}" append>华为</router-link>
14                     <router-link :to="{name: 'oneplus'}" append>一加</router-link>
15 
16                     <router-view></router-view>
17                 </div>
18                 `,
19         };
20         let HuaWei = {
21             template: `
22                     <div>
23                         <h3>华为手机</h3>
24                     </div>
25                 `,
26         };
27         let OnePlus = {
28             template: `
29                     <div>
30                         <h3>一加手机</h3>
31                     </div>
32                 `,
33 
34         let App = {
35             template: `
36                 <div>
37                     <router-link :to="{ name: 'home' }">首页</router-link>
38                     <router-link :to="{ name: 'phone'}">手机品牌</router-link>
39 
40                     <router-view></router-view>
41                 </div>
42                 `,
43         };
44 
45         let router = new VueRouter({
46         routes: [
47             {
48                 'name': 'home',
49                 'path': '/',
50                 'component': Home,
51             },
52             {
53                 'name': 'phone',
54                 'path': '/phone',
55                 'component': Phone,
56                 'children': [
57                     {
58                         'name':'huawei',
59                         'path': 'huawei',
60                         'component': HuaWei,
61                     },
62                     {
63                         'name':'oneplus',
64                         'path': 'oneplus',
65                         'component': OnePlus,
66                     },
67                 ],
68 
69             },
70         ]
71     });
    2.7 VueRouter之子路由重定向
 1     let router = new VueRouter({
 2             routes: [
 3                 {
 4                     name: 'home',
 5                     path: '/',
 6                     component: Home,
 7                 },
 8                 {
 9                     name: 'login',
10                     path: '/login',
11                     component: Login
12                 },
13                 {
14                     name: 'pay',
15                     path: '/pay',
16                     redirect: '/login',
17                     component: Pay,
18                 },
19             ]
20         });
    2.8 VueRouter之子路由的钩子函数
 1     let router = new VueRouter({
 2             routes: [
 3                 {
 4                     name: 'home',
 5                     path: '/',
 6                     component: Home,
 7                 },
 8                 {
 9                     name: 'login',
10                     path: '/login',
11                     component: Login
12                 },
13                 {
14                     name: 'pay',
15                     path: '/pay',
16                     meta: { required_login: true },
17                     component: Pay,
18                 },
19             ]
20         });
21 
22         // 通过router对象的beforeEach(function(to, from, next))
23         router.beforeEach(function (to, from, next) {
24            console.log("to: ", to);
25            console.log("from: ", from);
26            console.log("next: ", next);
27            if ( to.meta.required_login ) {
28                next('/login');
29            } else {
30                next();
31            }
32         });
    2.9 VueRouter之子路由的去 # 号
 1      let router = new VueRouter({
 2             mode:'history',
 3             routes: [
 4                 {
 5                     name: 'home',
 6                     path: '/',
 7                     component: Home,
 8                 },
 9                 {
10                     name: 'login',
11                     path: '/login',
12                     component: Login
13                 },
14                 {
15                     name: 'pay',
16                     path: '/pay',
17                     component: Pay,
18                 },
19             ]
20         });
 

转载于:https://www.cnblogs.com/xjmlove/p/10268118.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/278456.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

U Sparkle 开发者计划招募中!

向我们投稿吧 在此之前&#xff0c;我们有收到过几篇民间高手的投稿&#xff0c;如&#xff1a; USequencer 初识&#xff08;作者&#xff1a;焱燚(七火)&#xff09; Unity游戏界面解决方案: PSD For UGUI&#xff08;作者&#xff1a;张俊钦&#xff09; UGUI 降低填充率技巧…

如何添加引文标_如何在Google文档中查找和添加引文

如何添加引文标When writing papers, you need to generate a detailed and accurate list of all the sources you’ve cited in your paper. With Google Docs, you can easily find and then add citations to all of your research papers. 撰写论文时&#xff0c;您需要生…

Linux Centos下SQL Server 2017安装和配置

Linux Centos下SQL Server 2017安装和配置 原文:Linux Centos下SQL Server 2017安装和配置我们知道在Linux下安装服务有很多方式&#xff0c;最为简单的也就是yum安装&#xff0c;但是很多服务通过yum是无法安装的&#xff0c;如果想使用yum安装&#xff0c;需要指定yum安装仓库…

如何在Linux上使用端口敲门(以及为什么不应该这样做)

Photographee.eu/ShutterstockPhotographee.eu/ShutterstockPort knocking is a way to secure a server by closing firewall ports—even those you know will be used. Those ports are opened on demand if—and only if—the connection request provides the secret knoc…

小到年货大到产业,刘村长的扶贫模式有点厉害!

河北省阜平县平石头村的村民&#xff0c;今年春节再也不用头疼买什么年货&#xff0c;去哪买年货的问题了&#xff0c;因为他们的“村长”刘强东&#xff0c;给每户人家都送来了年货大礼包&#xff01;大礼包里不仅有牛奶、果汁、毛衣、长裤、波司登羽绒服、枕头、毛巾、炊大皇…

克隆ubuntu硬盘_使用Ubuntu Live CD克隆硬盘

克隆ubuntu硬盘Whether you’re setting up multiple computers or doing a full backup, cloning hard drives is a common maintenance task. Don’t bother burning a new boot CD or paying for new software – you can do it easily with your Ubuntu Live CD. 无论是设置…

从Boxee的Amie Street访问音乐

One of our favorite sites for discovering new music is Amie Street. Today we take a look at the Amie Street app for Boxee that allows you to access your favorite tunes from the Boxee interface. 我们最喜欢的发现新音乐的网站之一是Amie Street。 今天&#xff0…

如何在Word,Excel和PowerPoint 2010中裁剪图片

When you add pictures to your Office documents you might need to crop them to remove unwanted areas, or isolate a specific part. Today we’ll take a look at how to crop images in Office 2010. 将图片添加到Office文档时&#xff0c;可能需要裁剪它们以删除不需要…

在Windows 7 Media Center中创建音乐播放列表

One of the new features in Windows 7 Media Center is the ability to easily create music playlists without using Media Player. Today we’ll take a closer look at how to create them directly in Media Center. Windows 7 Media Center的新功能之一是无需使用Media …

SQL Server2008导入导出数据库

一、导出数据库 1.新建一个.bak的文本 右击数据库--》Tasks--》BackUp--》Remove原来的数据库--》Add后选择之前建立的.bak档 二、导入数据库 1.右击数据库--》Tasks--》Restore--》Database--》From device--》勾选数据库之后--》点击左上角Options--》点击 --》OK覆盖 转载于…

如何使YouTube视频连续循环播放

Should you need a YouTube video on a continuous loop, a few methods can help you keep repeating a video without having to start it over manually. Here’s how to do it. 如果您需要连续循环播放YouTube视频&#xff0c;可以采用以下几种方法来继续播放视频&#xff…

Android ABI

2019独角兽企业重金招聘Python工程师标准>>> 获取当前ABI var supportsABIs:Array<String>? null if(Build.VERSION.SDK_INT > 21) {supportsABIs Build.SUPPORTED_ABIS } var currentABI Build.CPU_ABI 通过Build可以获取当前手机支持的abi集以及cpu的…

nginx限流健康检查

Nginx原生限流模块:ngx_http_limit_conn_module模块根据前端请求域名或ip生成一个key&#xff0c;对于每个key对应的网络连接数进行限制。配置如下:http模块server模块#http模块内 http {include mime.types;default_type application/octet-stream;log_format main [$t…

如何在Ubuntu上创建桌面快捷方式

Desktop icons should be simple, but they’re not on Ubuntu 18.04 LTS and newer releases like Ubuntu 19.10. Follow these easy steps to get desktop shortcuts for your favorite applications, just like on other operating systems and other Linux desktops. 桌面图…

阿里再破记录!代表中国企业首次在这项国际比赛中摘得银牌!

2月9日在洛杉矶举行的第11届网络搜索与数据挖掘国际会议&#xff08;WSDM 2018&#xff09;上&#xff0c;公布了今年的WSDM Cup竞赛成绩&#xff0c;来自阿里巴巴的AliOS团队凭借优秀的算法能力&#xff0c;摘得榜眼。这是该赛事举办11届以来&#xff0c;中国企业在该赛事上首…

闪存驱动器_将闪存驱动器变成便携式Web服务器

闪存驱动器Portable applications are very useful for getting work done on the go, but how about portable servers? Here’s how you can turn your flash drive into a portable web server. 便携式应用程序对于在旅途中完成工作非常有用&#xff0c;但是便携式服务器呢…

Android中文API-ViewStub

ViewStub控件是一个不可见&#xff0c;0尺寸得惰性控件。当ViewStub控件设置可见&#xff0c;或者调用inflate()&#xff0c;并运行完毕之后&#xff0c;ViewStub所指定的layout资源就会被载入。这个ViewStub就会被新载入的layout文件取代。ViewStub也会从其父控件中移除。因此…

如何播放梅西百货的感恩节大游行2019

Macy’s梅西百货As we draw ever closer to the Thanksgiving holiday, multiple things come to mind: turkey, Black Friday, and the Macy’s Thanksgiving Day Parade. With that in mind, you might want to find a way to stream it for your family. 随着我们越来越接近…

AJAX入门这一篇就够了

什么是Ajax Ajax(Asynchronous JavaScript and XML) 异步JavaScript和XML Ajax实际上是下面这几种技术的融合&#xff1a; (1)XHTML和CSS的基于标准的表示技术(2)DOM进行动态显示和交互(3)XML和XSLT进行数据交换和处理(4)XMLHttpRequest进行异步数据检索(5)Javascript将以上技术…

如何在iPhone和iPad上允许“不受信任的快捷方式”

Khamosh PathakKhamosh PathakShortcuts is now a stock app in iOS 13, iPadOS 13, and beyond. Thanks to Apple’s stricter rules, any shortcut you download from the internet is blocked. Here’s how you can allow untrusted shortcuts on your iPhone or iPad. 现在…