1/在根目录创建一个tz.js
export default {
inserted(el) {
let switchPos = {
x: 10,
y: 85,
startX: 0,
startY: 0,
endX: 0,
endY: 0
}
el.addEventListener('touchstart', function (e) {
console.log(e)
switchPos.startX = e.touches[0].pageX
switchPos.startY = e.touches[0].pageY
})
el.addEventListener('touchend', function (e) {
switchPos.x = switchPos.endX
switchPos.y = switchPos.endY
switchPos.startX = 0
switchPos.startY = 0
})
el.addEventListener('touchmove', function (e) {
if (e.touches.length > 0) {
let offsetX = e.touches[0].pageX - switchPos.startX
let offsetY = e.touches[0].pageY - switchPos.startY
let x = switchPos.x - offsetX