简体   繁体   中英

How do I import tiff.js to my Vue project?

I want to view the .tif file in my Vue, so I try to use the tiff.js.
I try it in a "test.html" and use this to import the tiff.min.js.

<script src="./tiff.min.js">
</script>

However, there is no export from tiff.min.js so I don't know how to import that to my vue-cli.

<script>
export default ({
    name:"test",
    methods:{
        show(file){
            var reader = new FileReader();
  reader.onload = (function (theFile) {
    return function (e) {
      var buffer = e.target.result;
      var tiff = new Tiff({buffer: buffer});
      var canvas = tiff.toCanvas();
      var width = tiff.width();
      var height = tiff.height();
      if (canvas) {
        $('#output').empty().append(canvas);
      }
    };
    })(file);
    reader.readAsArrayBuffer(file);
        }

    
    }
})
</script>

there is something wrong:"Could not find name 'Tiff'. Did you mean 'tiff'?Vetur(2570)"

I think your problem is addressed in this StackOverflow question if you want to import the js file in your Vue component Importing javascript file for use within vue component

or your other options could be https://github.com/photopea/UTIF.js or https://github.com/image-js/tiff

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM