json|pub.js

js



const pub = {machine: "进入网站模板",// 公共接口地址_url: "",// 详细接口api地址_DetailApi: {}, /*** @param {*} that this指向* @param {*} _url 公共接口地址* @param {*} ur 具体接口地址* @param {*} data 形参* @param {*} cbk 回调*/_InitAjax(op) {$.ajax({type: "POST",contentType: "application/json",url: op._url + op.ur,data: JSON.stringify(op.data),error: function(request) {console.log("ajax请求失败"); },success: function(res) {// console.log(res); op.cbk(res); },fail: function(r) {console.log("Ajax的fail函数,", r); }}); },_InitAxios(op) {axios({url: op._url + op.ur,method: "post",data: JSON.stringify(op.data),headers: {"Content-Type": "application/json"}}).then(res => {console.log(res); op.cbk(res.data); }).catch(cat => {console.log("axios请求的catch错误"); }); }, /***截取页面链接中的参数*/_LinkParm: function(variable) {var query = window.location.search.substring(1); var vars = query.split("&"); for (var i = 0; i < vars.length; i++) {var pair = vars[i].split("="); if (pair[0] == variable) {return pair[1]; }}return false; }, /*** @param {*} event 输入框的值* @param {*} tgt 输入框绑定的值*/_CheckPhone(event, tgt) {console.log("检验手机号", event.target.value); var phone = /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/; if (!phone.test(tgt)) {alert("输入正确的手机号!"); tgt = ""; }}, /*** 数组转对象*/_change_obj(arr) {var _obj = {}; for (var it = 0; it < arr.length; it++) {for (var item in arr[it]) {_obj[item] = arr[it][item]; }}return _obj} // }; console.log(pub.machine); 复制代码


vue


【json|pub.js】
var app = new Vue({el: "#app",data: {},created() {console.log('进入自定义的vue函数中!')},methods: {}}); 复制代码

连接两个数组



/**** @param {*} old_r 原有数组* @param {*} new_r 新数组 需要连接到原有数组之上*/_Arr_concat(old_r,new_r){var arr = old_r; var _r = new_r; var _c = arr.concat(_r); old_r = _c; console.log('连接数组')return old_r},复制代码




    推荐阅读