问题:服务器端设置了options解决了405错误,但接收参数时又出现400错误
解决:因为数据传输格式不对
方法:
将传递的数据进行格式化
let params = new URLSearchParams()
params.append('umail', data['umail'])
params.append('upass', data['upass'])
return axios.post('/login', params
).then((res) => {
return Promise.resolve(res.data)
})
分类 "JavaScript" 下的文章
问题:vue如何进行字符串拼接?
解决:使用引号
方法:
vue将变量放入属性中时需要进行绑定
注意:
当字符串需要引号引起来
上述代码poster为变量
问题:在修改数据时,要根据数据对select选择框进行预设置数据
解决:使用jquery实现
方法:
一、使用后台语言进行判断
<select id="course">
<option value="2" {% if course == 2%}selected="selected"{%end%}>语文</option>
<option value="1" {% if course == 2%}selected="selected"{%end%}>数学</option>
<option value="3" {% if course == 2%}selected="selected"{%end%}>英语</option>
<option value="4" {% if course == 2%}selected="selected"{%end%}>物理</option>
<option value="5" {% if course == 2%}selected="selected"{%end%}>化学</option>
</select>
二、使用jquery进行判断并赋值
$("#course option").each(function(){
var course = $(this).val();
if(course == '{{ course }}'){
$("#course").val(course);
return false;
}
});
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JavaScript 图片截取效果</title>
</head>
<body>
<script type="text/javascript">
//一共3篇(html,drag.js,resize.js)
var isIE = (document.all) ? true : false;
var isIE6 = isIE && ([/MSIE (d).0/i.exec(navigator.userAgent)][0][1] == 6);
var $ = function (id) {
return "string" == typeof id ? document.getElementById(id) : id;
};
var Class = {
create: function() {
return function() { this.initialize.apply(this, arguments); }
}
}
var Extend = function(destination, source) {
for (var property in source) {
destination[property] = source[property];
}
}
<textarea name="个人介绍" cols="50" rows="6" class="bot" id="youbian" onkeyup="checkLength(this)"></textarea>
限制字符,显示剩余字符数,最大长度: 300
还剩: <span id="chLeft">300</span>
<script type="text/javascript">
function checkLength(which) {
var maxChars = 300;
if (which.value.length > maxChars)
which.value = which.value.substring(0,maxChars);
var curr = maxChars - which.value.length;
document.getElementById("chLeft").innerHTML = curr.toString();
}
</script>
下面的是限制字数(不含空格),最大字数为200字
function checkLength(which) {
var maxChars = 200;
var noSpace_val=which.value.replace(/(s*)/g,"");
var curr = maxChars - noSpace_val.length;
if(curr.toString() < 0){
var length=which.value.length;
which.value = which.value.substring(0,length+curr);
}else{
document.getElementById("chLeft").innerHTML = curr.toString();
}
}