您的位置:首页 > 产品设计 > UI/UE

Vue.prototype和sessionStorage的使用简介

2018-01-06 14:33 591 查看
1、Vue中的全局变量如何实现?

在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');
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: