Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

网页截图 #59

Open
Lee981265 opened this issue Dec 31, 2020 · 0 comments
Open

网页截图 #59

Lee981265 opened this issue Dec 31, 2020 · 0 comments

Comments

@Lee981265
Copy link
Member

import html2canvas from 'html2canvas'
console.log(this.getUrl(this.$refs.tzTable.$el))
getUrl(
    el: any,
    canvas: any = document.createElement('canvas'),
    option: any = {
      width: 500,
      height: 300,
      scale: 1,
      canvas,
      dpi: window.devicePixelRatio
    }
  ) {
    const context = canvas.getContext('2d')
    html2canvas(el, option).then(canvas => {
      context.mozImageSmoothingEnabled = false
      context.webkitImageSmoothingEnabled = false
      context.msImageSmoothingEnabled = false
      context.imageSmoothingEnabled = false
      let dataUrl = canvas.toDataURL('image/jpeg', 1.0)
      let newImg = document.createElement('img')
      newImg.src = dataUrl
      console.log('dataUrl:',dataUrl)
      // 输出在控制台
      console.log(
        '%c ',
        `background:url(${dataUrl}) no-repeat;background-size:200px; margin:5px 0;
  padding:0 0 162px 200px;
  border-radius:10px;
  overflow:hidden;`
      )
      newImg.width = option.width
      newImg.height = option.height
    })
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant