欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Vue實(shí)現(xiàn)單點(diǎn)登錄控件的完整代碼

 更新時間:2021年11月05日 09:41:17   作者:林恒  
這里提供一個Vue單點(diǎn)登錄的demo給大家參考,對Vue實(shí)現(xiàn)單點(diǎn)登錄控件的完整代碼感興趣的朋友跟隨小編一起看看吧

這里提供一個Vue單點(diǎn)登錄的demo給大家參考,希望對想了解的朋友有一些幫助。具體的原理大家可以查看我的上篇文章

vue實(shí)現(xiàn)單點(diǎn)登錄的N種方式廢話不多少直接上代碼這里分兩套系統(tǒng),一是登錄系統(tǒng)的主體端,我們所有子系統(tǒng)或者關(guān)聯(lián)系統(tǒng)的登錄流程,全部在這里完成

具體代碼如下:login.vue

<template>
  <div class="hello">
    <h1>{{ msg }}</h1>
    <button @click="handleLogin">點(diǎn)擊登錄</button>
    <button @click="rethome">返回之前頁面</button>
  </div>
</template>
 
<script>
import Cookies from 'js-cookie'
export default {
  name: 'home',
  data () {
    return {
      msg: '系統(tǒng)一:統(tǒng)一登錄頁面',
    }
  },
  mounted(){
    const token = Cookies.get('app.token');
    if(token){
      this.rethome();
    }
  },
  methods: {
        handleLogin() {
        var token = this.randomString();
        Cookies.set('app.token',token, { expires: 1000, path: '/',domain: '.xxx,com' })//寫上你的網(wǎng)站主域名
        if(Cookies.get('app.returl')){
          Cookies.set('app.loginname','系統(tǒng)二', { expires: 1000, path: '/',domain: '.xxx,com' })//寫上你的網(wǎng)站主域名
        }else{
          Cookies.set('app.loginname','系統(tǒng)一', { expires: 1000, path: '/',domain: '.xxx,com' })//寫上你的網(wǎng)站主域名
        }
        this.rethome();
    },
    rethome(){
      var returl = Cookies.get('app.returl');
        if(returl){
          Cookies.set('app.returl','', { expires: 1000, path: '/',domain: '.xxx,com' })//寫上你的網(wǎng)站主域名
           window.open(returl,"_parent");
        }else{
          this.$router.push("/");
        }
    },
    randomString(e) {
        e = e || 32;
        var t = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678",
        a = t.length,
        n = "";
        for (var i = 0; i < e; i++) n += t.charAt(Math.floor(Math.random() * a));
        return n
    }
    }
}
</script>
 
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1, h2 {
  font-weight: normal;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>

home.vue

<template>
  <div class="hello">
    <h1>{{ msg }}</h1>
    <h3>用戶信息為:{{token}}</h3>
    <h3>登錄地點(diǎn):{{loginname}}</h3>
    <button @click="logout">登出</button>
  </div>
</template>
 
<script>
import Cookies from 'js-cookie'
 
export default {
  name: 'home',
  data () {
    return {
      msg: '系統(tǒng)一主頁面',
      token:'',
      loginname:''
    }
  },
  mounted(){
    const token = Cookies.get('app.token');
    this.token = token;
    const loginname = Cookies.get('app.loginname');
    this.loginname = loginname;
    console.log(token);
    if(!token){
      this.$router.push("/login");
    }else{
      this.rethome()
    }
  },
  methods: {
    logout(){
        Cookies.set('app.token','', { expires: 1000, path: '/',domain: '.xxx,com' })//寫上你的網(wǎng)站主域名
        Cookies.set('app.loginname','', { expires: 1000, path: '/',domain: '.xxx,com' })//寫上你的網(wǎng)站主域名
        this.$router.go(0)
    },
    rethome(){
      var returl = Cookies.get('app.returl');
        if(returl){
          Cookies.set('app.returl','', { expires: 1000, path: '/',domain: '.xxx,com' })//寫上你的網(wǎng)站主域名
          window.open(returl,"_parent");
        }else{
        }
    },
  }
}
</script>
 
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1, h2 {
  font-weight: normal;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>

登錄系統(tǒng)完成后,我們的步驟已經(jīng)完成一半,接下來是調(diào)用端的組件制造及調(diào)用方法,這里給大家展示我的案例控件代碼

<template>
  <div class="hello" v-show="false">
  </div>
</template>
 
<script>
import Cookies from 'js-cookie'
export default {
  props:{
        type:{
            type:String,
            default:'getdata'
    }
  },
  name: 'home',
  data () {
    return {
      token:'',
      loginname:''
    }
  },
  mounted(){
    const token = Cookies.get('app.token');
    this.token = token?token:'未登陸';
    const loginname = Cookies.get('app.loginname');
    this.loginname = loginname?loginname:'未登陸';
    this.returnFun()
  },
  methods: {
        returnFun(){
      var data = {
        token:this.token,
        loginname:this.loginname
      }
      this.$emit("clickFun",data);
    }
  },
  watch: {
      'type': function (val) {
        const token = Cookies.get('app.token');
        this.token = token?token:'未登陸';
        const loginname = Cookies.get('app.loginname');
        this.loginname = loginname?loginname:'未登陸';
        switch(val){
          case 'login':
          console.log(token);
          if(token !=''){
            this.returnFun();
          }else{
            Cookies.set('app.returl','本地路由', { expires: 1000, path: '/',domain: '.xxx,com' })//寫上你的網(wǎng)站主域名
            window.open('登陸系統(tǒng)地址',"_parent");
          }
          break;
          case 'logout':
          Cookies.set('app.token','', { expires: 1000, path: '/',domain: '.xxx,com' })//寫上你的網(wǎng)站主域名
          Cookies.set('app.loginname','', { expires: 1000, path: '/',domain: '.xxx,com' })//寫上你的網(wǎng)站主域名;
          this.token = '未登陸';
          this.loginname ='未登陸';
          this.returnFun();
          break;
          case 'getdata':
          this.returnFun();
          break;
        }
      }
  }
}
</script>
 
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1, h2 {
  font-weight: normal;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>

調(diào)用端代碼案例如下:

<template>
  <div class="hello">
    <login @clickFun="returnFun" :type ="type"></login>
    <h1>{{ msg }}</h1>
    <h3>用戶信息為:{{token}}</h3>
    <h3>登錄地點(diǎn):{{loginname}}</h3>
    <button @click="login">登陸</button>
    <button @click="logout">登出</button>
  </div>
</template>
 
<script>
import Cookies from 'js-cookie'
import login from '@/pages/login'
 
export default {
  name: 'home',
  data () {
    return {
      msg: '系統(tǒng)二:父組件頁面',
      token:'未登陸',
      loginname:'未登陸',
      type:'getdata',
    }
  },
  mounted(){
  },
  methods: {
    login(){
      this.type = "login";
    },
    logout(){
      this.type = "logout";
    },
    returnFun(value){
        console.log(value,"子組件返回值")
                const token = value.token;
        this.token = token?token:'未登陸';
        const loginname = value.loginname;
        this.loginname = loginname?loginname:'未登陸';
        }
  },
  components:{
            login
    }
}
</script>
 
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1, h2 {
  font-weight: normal;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>

到這里,一個簡易單點(diǎn)登錄系統(tǒng)的搭建已經(jīng)完成,大家可以照著這個思路,繼續(xù)完善最終制作成對應(yīng)的控件。如果對您有所幫助,歡迎您點(diǎn)個關(guān)注,我會定時更新技術(shù)文檔,大家一起討論學(xué)習(xí),一起進(jìn)步。

到此這篇關(guān)于Vue單點(diǎn)登錄控件代碼分享 的文章就介紹到這了,更多相關(guān)Vue單點(diǎn)登錄內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • vue3關(guān)鍵字高亮指令的實(shí)現(xiàn)詳解

    vue3關(guān)鍵字高亮指令的實(shí)現(xiàn)詳解

    這篇文章主要為大家詳細(xì)介紹了vue3實(shí)現(xiàn)關(guān)鍵字高亮指令的相關(guān)資料,w文中的示例代碼講解詳細(xì),具有一定的借鑒價值,有需要的小伙伴可以參考一下
    2023-11-11
  • ???????基于el-table和el-pagination實(shí)現(xiàn)數(shù)據(jù)的分頁效果

    ???????基于el-table和el-pagination實(shí)現(xiàn)數(shù)據(jù)的分頁效果

    本文主要介紹了???????基于el-table和el-pagination實(shí)現(xiàn)數(shù)據(jù)的分頁效果,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-08-08
  • vue設(shè)置頁面背景及背景圖片簡單示例

    vue設(shè)置頁面背景及背景圖片簡單示例

    這篇文章主要給大家介紹了關(guān)于vue設(shè)置頁面背景及背景圖片的相關(guān)資料,在Vue項目開發(fā)中我們經(jīng)常要向頁面中添加背景圖片,文中通過代碼示例介紹的非常詳細(xì),需要的朋友可以參考下
    2023-08-08
  • Vuex數(shù)據(jù)的存儲與獲取方式

    Vuex數(shù)據(jù)的存儲與獲取方式

    這篇文章主要介紹了Vuex數(shù)據(jù)的存儲與獲取方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-06-06
  • 基于Vue3實(shí)現(xiàn)數(shù)字華容道游戲的示例代碼

    基于Vue3實(shí)現(xiàn)數(shù)字華容道游戲的示例代碼

    這篇文章主要為大家詳細(xì)介紹了如何利用Vue編寫一個數(shù)字華容道游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-04-04
  • vue報錯"vue-cli-service‘不是內(nèi)部或外部命令,也不是...”的解決辦法

    vue報錯"vue-cli-service‘不是內(nèi)部或外部命令,也不是...”的解決辦法

    這篇文章主要介紹了vue報錯"vue-cli-service‘不是內(nèi)部或外部命令,也不是...”的解決辦法,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-01-01
  • vue中的事件加判斷條件如何進(jìn)行選擇性點(diǎn)擊

    vue中的事件加判斷條件如何進(jìn)行選擇性點(diǎn)擊

    這篇文章主要介紹了vue中的事件加判斷條件如何進(jìn)行選擇性點(diǎn)擊方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-03-03
  • vue中的stylus及stylus-loader版本問題

    vue中的stylus及stylus-loader版本問題

    這篇文章主要介紹了vue中的stylus及stylus-loader版本問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • 詳解Vue計算屬性原理

    詳解Vue計算屬性原理

    計算屬性是Vue中比較好用的API,開發(fā)者可以利用計算屬將復(fù)雜的計算進(jìn)行緩存,同時基于它的響應(yīng)式特性,我們無需關(guān)注數(shù)據(jù)更新問題,但需要注意的是,計算屬性是惰性求值的,本文將詳細(xì)介紹計算屬性的實(shí)現(xiàn)原理,需要的朋友可以參考下
    2023-05-05
  • vue中radio單選框如何實(shí)現(xiàn)取消選中狀態(tài)問題

    vue中radio單選框如何實(shí)現(xiàn)取消選中狀態(tài)問題

    這篇文章主要介紹了vue中radio單選框如何實(shí)現(xiàn)取消選中狀態(tài)問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-05-05

最新評論