2017-06-01 54 views
0

這是我的代碼auth.js(KOA)Vue公司無法導入jsonwebtoken,它表明,未發現有denpendencies:網絡DNS

const auth=require('../function/auth'); 
const jwt = require('jsonwebtoken'); 
const bcrypt = require('bcryptjs'); 

var log = async (ctx,next)=>{ 

    var Account=ctx.request.body.account, 
      Password=ctx.request.body.password, 
      query={ 
       account:Account, 
      } 
     var data=await auth.log(query); 

     if(data.length>0){ 
      if(bcrypt.compareSync(Password,data[0].password)){ 
       const userToken={ 
        account:data[0].account, 
        id:data[0]._id 
       } 
       const secret = 'vue-koa-demo'; 
       const token =jwt.sign(userToken,secret); 
       ctx.response.type='application/json' 
       ctx.response.body={ 
        sta:true, 
        token:token} 
      } 
      else if(!bcrypt.compareSync(Password,data[0].password)){ 
       ctx.response.type='application/json' 
       ctx.response.body={ 
        sta:false, 
        info:'密碼錯了'} 


      } 

     }if(data.length==0){ 
       ctx.response.type='application/json' 
       ctx.response.body={ 
        sta:false, 
        info:'賬號不存在'} 
     } 

} 

,這是我TodoList.vue(VUE)

... 
<script> 
import jwt from 'jsonwebtoken' 
export default { 
    created() { // 組件創建時調用 
    const userInfo = this.getUserInfo() 
    if (userInfo !== null) { 
     this.id = userInfo.id 
     this.name = userInfo.name 
    } else { 
     this.id = '' 
     this.name = '' 
    } 
    }, 
    data() { 
    return { 
     name: 'Molunerfinn', 
     todos: '', 
     activeName: 'first', 
     list: [], 
     count: 0 
    } 
    }, 
    computed: { // 計算屬性用於計算是否已經完成了所有任務 
    Done() { 
     let count = 0 
     let length = this.list.length 
     for (let i in this.list) { 
     this.list[i].status === true ? count += 1 : '' 
     } 
     this.count = count 
     if (count === length || length === 0) { 
     return true 
     } else { 
     return false 
     } 
    } 
    }, 
    methods: { 
    addTodos() { 
     if (this.todos === '') { 
     return 
     } 
     let obj = { 
     status: false, 
     content: this.todos 
     } 
     this.list.push(obj) 
     this.todos = '' 
    }, 
    finished (index) { 
     this.$set(this.list[index], 'status', true) 
     this.$message({ 
     type: 'success', 
     message: '任務完成' 
     }) 
    }, 
    remove (index) { 
     this.list.splice(index, 1) 
     this.$message({ 
     type: 'info', 
     message: '任務刪除' 
     }) 
    }, 
    restore (index) { 
     this.$set(this.list[index], 'status', false) 
     this.$message({ 
     type: 'info', 
     message: '任務還原' 
     }) 
    }, 
    getUserInfo() { 
     const token = sessionStorage.getItem('my-token') 
     if (token !== null) { 
     let decode = jwt.verify(token, 'vue-koa-demo') 
     return decode 
     } else { 
     return null 
     } 
    } 
    } 
} 
</script> 
... 

然後在vsCODE NPM運行開發,

HESE依賴均未發現:

  • 淨./~/joi/lib/string.js
  • DNS在./~/isemail/lib/isemail.js

要安裝它們,你可以運行:NPM安裝 - - 保存網絡DNS

和我嘗試,但現在的問題是

這些依賴關係,未發現:

  • FS在./~/native-dns/lib/server.js ./~/native-dns/lib/platform.js
  • DGRAM,./~/native-dns/lib/utils。 JS和1個其他

要安裝它們,你可以運行:NPM安裝--save FS DGRAM

+0

PS:jwt在auth.js中運行良好, –

回答