I am facing an issue when trying to pass an event into my Vue component. No matter what method I try, I keep getting a "TypeError: Cannot read property 'preventDefault' of undefined" error.
Here is the code snippet for my Vue component:
Vue.component('jl-asset-list', {
created() {
console.log(this.asset);
console.log(this.canModify);
console.log(this.editSiteAssetAllowed);
console.log(this.event);
},
props: {
hasCompleteTask: {
default: false,
type: Boolean
},
asset: {
type: Object,
required: true
}
},
methods: {
EditSiteAsset(asset, event) {
event.preventDefault();
event.stopPropagation();
var context = this;
context.SelectedSiteAsset = asset;
var target = event.target || event.srcElement;
var icon = $(target).closest('.jobasset_edit');
icon.prop('disabled', true);
this.$emit('edit-site-asset', asset);
},
EditJobAsset(asset) {
this.$emit('edit-job-asset', asset);
},
HighlightAsset(asset) {
this.$emit('highlight-asset', asset);
}
}
Below is the relevant part of my CSHTML:
<jl-asset-list v-for="(siteAsset, index) in FilteredSiteAssets"
inline-template
v-bind:asset="siteAsset"
v-bind:canModify="Model.CanModify"
v-bind:editSiteAssetAllowed="Model.EditSiteAssetAllowed"
v-on:highlight-asset="HighlightAsset"
v-on:edit-site-asset="EditSiteAsset">
@Html.Partial("~/Views/Asset/Templates/_AssestList.cshtml")
</jl-asset-list>
This is how I have defined my template:
<a v-on:click="EditSiteAsset(asset)"
class="jobasset_edit jl-icon-orange" data-toggle="tooltip" data-placement="top" data-original-title="Edit">
<i class="mdi mdi-pencil-circle mdi-24px"></i>
</a>
I have also tried using EditSiteAsset($event) in v-on and emitting 'edit-site-asset' from the Vue component, but it doesn't work either.
The EditSiteEvent() method within my Vue component requires an event to function properly.
EditSiteAsset: function (data, event) {
event.preventDefault();
event.stopPropagation();
var context = this;
context.SelectedSiteAsset = data;
var target = event.target || event.srcElement;
var icon = $(target).closest('.jobasset_edit');
icon.prop('disabled', true);
GetSwitchModalPartial(
'/Asset/UpdateSiteAsset?siteId=' + context.Model.SiteId + '&id=' + data.Id,
{ forJobAsset: true },
function (data) {
icon.prop('disabled', false);
});
return false;
},