vue实现水印

setWatermarkContent(content) {
        let id = "1.23452384164.1223412415";
        if (document.getElementById(id) !== null) {
          document.body.removeChild(document.getElementById(id));
        }

        let ele = document.createElement("canvas");
        ele.width = 250;
        ele.height = 150;

        let getCanvas = ele.getContext("2d");
        this.customcxt = getCanvas;
        getCanvas.rotate((-20 * Math.PI) / 180);
        getCanvas.font = "20px Vedana";
        getCanvas.fillStyle = "rgba(200, 200, 200, 0.35)";
        getCanvas.textAlign = "center";
        getCanvas.textBaseline = "Middle";
        getCanvas.fillText(content, ele.width / 6, ele.height / 2);
        // getCanvas.fillText(content2, ele.width / 6, (ele.height + 40) / 2)

        let div = document.createElement("div");
        div.id = id;
        div.style.pointerEvents = "none";
        div.style.top = "82px";
        div.style.left = "0px";
        div.style.position = "fixed";
        div.style.zIndex = "100000";
        div.style.width = document.documentElement.clientWidth + "px";
        div.style.height = document.documentElement.clientHeight + "px";
        div.style.background =
          "url(" + ele.toDataURL("image/png") + ") left top repeat";
        document.getElementById("pdfID").appendChild(div);
        return id;
      },

你可能感兴趣的:(vue,vue.js,前端,javascript)