写一个px,vw互相转换小工具碰到的问题。记录一下
html 代码
图片宽度px
图片高度 px
宽度 px
宽度 vw
高度 px
高度 vh
关键javascrip
methods: {
//生成vw和vh通用方法
computeV(img,px,key){
console.log("各种this",img,px,key);
percent = img / 100;
key = px / percent;
console.log("结果key",key);
return key;
},
//生成px通用方法
computeP(img,v){
temp = img / 100;
cache = temp * v;
console.log("缓存",cache);
return cache;
}
},
watch: {
pxWidth(val,oldVal){
//刚开始计算vw的写法
// vw = this.imgWidth / 100
// vwResult = this.pxWidth /