vue小知识

vue小知识


一、后台@RequestParam接收参数,vue前台传递参数

1.后台的接口是这样的

@PostMapping("/disclosure")
public ApiResult<Boolean> disclosureReceviceVul(@RequestParam("id") String id) {
    boolean flag = receviceVulService.disclosureReceviceVul(id);
    return ApiResult.result(flag);
}

2.前台接口js文件传递的接口

export function disclosureGeneral(param) {
  return request({
    url: '/api/receviceGeneralVul/disclosure',
    method: 'post',
    data: param
  })
}

3.vue调用接口,要import接口进页面

handleDisclosure(id) {
	const params = new FormData()
	params.append('id', id)
	disclosureGeneral(params).then(response => {
		if (response.success) {
	        this.msgSuccess('成功')
	    }
	})
}

4.整个form中的参数全部append到params中去

const formData = this.form
const params = new FormData()
Object.keys(formData).forEach((key) => {
  params.append(key, formData[key])
})

二、vue前端实现定时器轮询

轮询之后在其他页面进行销毁 只在本界面执行

// 实现定时器轮询 只在本界面执行这个定时器
const timer = setInterval(() => {
  console.log(1)
}, 1000)
this.$once('hook:beforeDestroy', () => {
  clearInterval(timer)
})

三、判断是否为空Object

if (Object.keys(res.data).length === 0) {
	// 业务逻辑
}

四、实现文本复制

1.下载vue-clipboard2

npm install vue-clipboard2 --save

2.在main.js中添加

import VueClipboard from 'vue-clipboard2'

Vue.use(VueClipboard)

3.实现复制

<el-button type="primary" @click="copyCode">Copy code</el-button>

copyCode() {
  this.$copyText(this.text).then(
    res => {
      this.msgSuccess('Copy successfully. You can paste it directly')
    },
    err => {
      this.msgError('Copy failed')
    })
}

4.将div滚动条拉到最底部

scrollToBottom() {
  this.$nextTick(() => {
    let container = this.$el.querySelector("#centerContent");
    container.scrollTop = container.scrollHeight;
  });
}

五、数组操作

# 数组末尾添加
push()
# 数组末尾取出
pop()           
# 数组开头取出
shift()          
# 数组开头添加
unshift()      
# 删除并插入
splice()        
# 排序
sort()           
# 数组顺序颠倒
reverse()     
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值