vue:h5视频横屏设置

下载current-device包,获取当前环境(web/移动)、状态(横屏/竖屏)
npm i current-device
以下是功能代码setSize.js文件
import { onBeforeMount, onBeforeUnmount, reactive } from 'vue'
import device from "current-device";

export const useAutoSize = () => {
    const styles = reactive({
        width: '100%',
        height: '100%',
        transform: 'rotate(0deg)',
        'transform-origin': '',
        fontSize: '16px',
    })

    onBeforeMount(() => {
        autoReSize();
        device.onChangeOrientation(autoReSize);
        window.addEventListener("resize", autoReSize);
    })

    onBeforeUnmount(() => {
        window.removeEventListener("resize", autoReSize);
    })


    function autoReSize() {
        let designWidth = 1920, rem2px = 100, unit = 'vw'
        if (device.mobile() && device.portrait()) {
            styles.width = window.innerHeight + 'px'
            styles.height = window.innerWidth + 'px'
            styles.transform = 'rotate(90deg)'
            styles['transform-origin'] = `${window.innerWidth / 2}px center`
            unit = 'vh'
        } else {
            styles.width = '100%'
            styles.height = '100%'
            styles.transform = 'rotate(0deg)'
            styles['transform-origin'] = ''
        }
        styles.fontSize = `${(100 / designWidth) * rem2px}${unit}`
    }

    return styles
}
最后在页面index.vue中使用
<template>
  <div :style="styles" class="version-four-container">
    // ...content
  </div>
</template>
<script setup>
import { useAutoSize } from './setSize'
const styles = useAutoSize();
  // ...content
</script>

<style lang="less" scoped>
  // ...content
</style>

你可以使用HTML5的File API和XMLHttpRequest对象来上传图片。以下是一个简单的示例: 1. 在Vue组件中添加一个input标签并设置type为file。 ```html <template> <div> <input type="file" @change="uploadImage"> </div> </template> ``` 2. 在Vue组件的methods中定义uploadImage方法,该方法将调用File API来获取选定的文件,并使用XMLHttpRequest对象将其上传到服务器。 ```javascript methods: { uploadImage(event) { const file = event.target.files[0]; const formData = new FormData(); formData.append('image', file); const xhr = new XMLHttpRequest(); xhr.open('POST', '/upload/image'); xhr.onload = () => { if (xhr.status === 200) { console.log('Image uploaded successfully!'); } else { console.error('Failed to upload image.'); } }; xhr.send(formData); } } ``` 3. 在服务器端接收上传的文件并将其保存到服务器上的某个位置。 ```javascript const express = require('express'); const multer = require('multer'); const app = express(); const upload = multer({ dest: 'uploads/' }); app.post('/upload/image', upload.single('image'), (req, res) => { console.log(req.file); // { fieldname: 'image', originalname: 'example.jpg', encoding: '7bit', mimetype: 'image/jpeg', destination: 'uploads/', filename: 'f3b2e66a1b8ebe6d3d57f28b3688c5a8', path: 'uploads/f3b2e66a1b8ebe6d3d57f28b3688c5a8', size: 92976 } res.send('Image uploaded successfully!'); }); app.listen(3000, () => { console.log('Server started on port 3000'); }); ``` 以上示例仅供参考,具体实现可能因应用场景而有所不同。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值