Vue.prototype和sessionStorage的使用简介
2018-01-06 14:33
591 查看
1、Vue中的全局变量如何实现?
在Vue中多个页面间的变量的保存与读取如何实现?
2、Vue中的全局变量是通过 Vue.prototype实现的
如我们的客户端数据接口BASE_URLD main.js中定义如下:
在其他页面引用如下:
3、通过sessionStorage实现在Vue中多个页面间的变量的保存与读取
如在登录成功后,我们将用户名保存在sessionStorage中
在其他页面,我们通过sessionStorage取出用户名
在Vue中多个页面间的变量的保存与读取如何实现?
2、Vue中的全局变量是通过 Vue.prototype实现的
如我们的客户端数据接口BASE_URLD main.js中定义如下:
Vue.prototype.BASE_URLD = 'http://127.0.0.1:8080';
在其他页面引用如下:
<script> methods: { getList(){ this.$http.post(this.BASE_URLD + '/mobile/getList.do',{type:1) .then(function (res) { }) .catch(function (error) { }); } } </script>
3、通过sessionStorage实现在Vue中多个页面间的变量的保存与读取
如在登录成功后,我们将用户名保存在sessionStorage中
sessionStorage.setItem('userName', res.data.userName);
在其他页面,我们通过sessionStorage取出用户名
var userName = sessionStorage.getItem('userName');
相关文章推荐
- Vue中localstorage和sessionstorage的使用规范
- vue中使用sessionStorage记住密码功能
- vue项目中调用百度地图API使用简介
- 详解Vue中localstorage和sessionstorage的使用
- 【原】基于64位Centos6.2的mcrouter使用简介
- C++ bitset类的使用与简介 [转载]
- vue + ajax + php 接口的使用小接
- ant使用简介
- MySQL GUI Tools 使用简介
- Qt简介以及如何配置Qt使用VS2010进行开发
- ApacheBench(ab)使用简介
- git使用简介
- 【Git】01、GIT简介及Github的使用
- vue如何安装使用Quill富文本编辑器
- MongoDB入门1――简介、安装及基本使用
- Google App Engine使用简介
- VUE 使用中踩过的坑
- (转) RSA-Tool 2 使用简介
- JavaScript的prototype的属性和方法-使用
- ASIHTTPRequest类库简介和使用说明