I am a beginner in vue.js and I am currently facing an issue with making a get request from a field that has a v-model="embed.url" after pasting a link. The paste event works fine, but I'm struggling to reference the input with v-model="embed.url" and retrieve the data.
Every time I attempt the code below, I encounter the following errors: [Vue warn]: Error in v-on handler: "ReferenceError: embed is not defined" and ReferenceError: "embed is not defined"
This is my Vue code:
<script type="text/javascript">
axios.defaults.xsrfHeaderName = "X-CSRFToken";
new Vue({
el: '#app',
delimiters: ['!!', '!!'],
data () {
return {
embed: {
url: '',
title: '',
description: '',
type: '',
thumbnail_url: '',
html: '',
},
isPaste: false,
embedsinfo: [],
}
},
methods: {
formSubmit(e) {
e.preventDefault();
let currentObj = this;
axios.post('http://wegemoc.local:8000/recipes/recipe/embed/add/', {
url: this.url,
})
.then(function (response) {
currentObj.output = response.data;
})
.catch(function (error) {
currentObj.output = error;
});
},
paste() {
this.isPaste = true;
},
input() {
if (this.isPaste) {
axios.get('http://iframe.ly/api/oembed?url=' + embed.url + '&api_key=493c9ebbdfcbdac2a10d6b')
.then(response => (this.embedsinfo = response))
isPaste = false;
}
}
},
});
This is my form:
<div id="app">
!! embedsinfo.title !!
<form method="post" class="margin-bottom-25" @submit="formSubmit">
{% csrf_token %}
<div class="form-group">
<label for="formGroupExampleInput">Recipe URL*</label>
<input type="url" class="form-control" placeholder="URL" @paste="paste" @input="input" v-model="embed.url">
</div>
<div class="form-group">
<label for="formGroupExampleInput2">Title</label>
<input class="form-control" placeholder="Title" v-model="embed.title">
</div>
<div class="form-group">
<label for="formGroupExampleInput2">Description</label>
<input type="textarea" class="form-control" id="formGroupExampleInput2" placeholder="Description" v-model="embed.description">
</div>
<div class="form-group">
<label for="formGroupExampleInput2">Thumbnail URL</label>
<input type="text" class="form-control" id="formGroupExampleInput2" placeholder="Thumbnail URL" v-model="embed.thumbnail_url">
</div>
<button type="submit" class="btn btn-success-gradiant">Add Link</button>
</form>
</div>