You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
cloudnote_web/plugins/global.js

48 lines
1.3 KiB

import Vue from 'vue'
Vue.prototype.GLOBAL ={
//用户cookie
user_key:'user',
//服务器地址
server_address:'http://127.0.0.1:8080',
// 检查元素可见
visible_in_container:function(p,e) {
var z = p.getBoundingClientRect();
var r = e.getBoundingClientRect();
// Check style visiblilty and off-limits
return !(r.top > z.bottom || r.bottom < z.top ||
r.left > z.right || r.right < z.left);
},
fetchJSON(url,method, form, success){
fetch(this.server_address + url, {
body:JSON.stringify(form),
method: method,
headers: {
'Content-Type': 'application/json'
},
credentials: "include"
}).then(res=>res.json()).then(res=>success(res)).catch(err=>{
console.error(err)
})
},
fetchGet(url,params,success){
if (params) {
let paramsArray = [];
//拼接参数
Object.keys(params).forEach(key => paramsArray.push(key + '=' + params[key]))
if (url.search(/\?/) === -1) {
url += '?' + paramsArray.join('&')
} else {
url += '&' + paramsArray.join('&')
}
}
fetch(this.server_address + url, {
method:'GET',
credentials: "include"
}).then(res=>res.json()).then(res=>success(res)).catch(err=>{
console.error(err)
})
}
}