I'm currently working with an npm package that shortens URLs but I'm struggling because there isn't much documentation available. The package takes the "this.src" URL and shortens it, but when I try to use the "url" element in HTML, it returns undefined. Can anyone help me figure out how to properly utilize this package?
<template>
<div id="image">
<h2>Upload Successful</h2>
<a target="_blank" :href="src">Image Link</a>
<button @click="shorter">Short URL</button>
<p>{{ urlShare }}DD</p> //GIVES UNDEFINED
<div class="img">
<a target="_blank" :href="src"> <img :src="src" alt="" /> </a>
</div>
</div>
</template>
<script>
var shortUrl = require("node-url-shortener");
export default {
name: "Image",
props: ["src"],
data() {
return {
urlShare: null, //GIVES UNDEFINED
};
},
methods: {
shorter() {
this.urlShare = shortUrl.short(this.src, function (err, url) {
return url;
});
console.log(this.urlShare); //GIVES UNDEFINED
},
},
};
</script>