当前位置:网站首页>Adjust SVG width and height

Adjust SVG width and height

2022-06-12 08:36:00 Month to month better

svg It is obtained from the back-end data , Get svg Then append it to wechat_qrcode Rendering in tags , Back end svg The width and height displayed are 207207 Do not conform to the UI280280, It is necessary to adjust its svg Wide and high
 Insert picture description here
adjustment svg Width and height must be combined viewBox Use

<li id="wechat_qrcode" ref="wechat_qrcode"></li>
mounted(){
    
	this.fetchclientqrcode()
}
methods:{
    
	fetchclientqrcode() {
    
      return this.$http
        .get(`/api/qrcode`)
        .delegateTo(api_request)
        .then((res) => {
    
          this.$nextTick(() => {
    
            this.$refs.wechat_qrcode.innerHTML = res.qrcode;
            const svg = document.getElementsByClassName("pyqrcode")[0];
            svg.setAttribute("width","280");
            svg.setAttribute("height","280");
            svg.setAttribute("viewBox","0 0 210 210");
          });
        })
        .catch(({
     code, message }) => {
    
          throw ` Failed to get data :${
     this.$t("api." + code)},  Additional information : ${
     this.$t( "api." + typeof message === "string" ? message : JSON.stringify(message) )}`;
        })
        .delegateTo(this.$snackbar.delegateError);
    }
}

 Insert picture description here

原网站

版权声明
本文为[Month to month better]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/163/202206120828078819.html