Answer the question
In order to leave comments, you need to log in
How to trigger a function on click on any link?
Good afternoon!
There is a component:
<template>
<div id="app">
<div class="wrapper">
<!-- Sidebar -->
<nav id="sidebar">
<ul class="list-unstyled components">
<b-nav-item :to="{name: 'AdmissionActList'}" v-on:click.prevent="sidebarCollapse">link</b-nav-item>
<b-nav-item :to="{name: 'ShiftsTask'}" v-on:click.prevent="sidebarCollapse">link</b-nav-item>
<b-nav-item :to="{name: 'MaterialTransferActList'}" v-on:click.prevent="sidebarCollapse">link</b-nav-item>
<b-nav-item v-on:click.prevent="sidebarCollapse">Выпуск</b-nav-item>
<b-nav-item :to="{name: 'StorageReportIndex'}" v-on:click.prevent="sidebarCollapse">link</b-nav-item>
<b-nav-item :to="{name: 'ProductionPlanList'}" v-on:click.prevent="sidebarCollapse">link</b-nav-item>
<b-nav-item :to="{name: 'BarcodeCreate'}" v-on:click.prevent="sidebarCollapse">link</b-nav-item>
</ul>
</nav>
</div>
</div>
<template>
<script>
export default {
name: 'App',
data() {
return {
isActive: false,
dropDown:false
}
},
methods: {
sidebarCollapse: function() {
this.isActive = !this.isActive;
},
dropdownCollapse: function() {
this.dropDown = !this.dropDown;
}
},
}
</script>
v-on:click.prevent="sidebarCollapse"
Answer the question
In order to leave comments, you need to log in
Create links with v-for
.
In data you will have an array:
links: [
{ title: 'link #1', to: { name: 'AdmissionActList' } },
{ title: 'link #2', to: { name: 'ShiftsTask' } },
// ну и так далее
],
<ul class="list-unstyled components">
<b-nav-item
v-for="link in links"
:to="link.to"
@click.prevent="sidebarCollapse"
>{{ link.title }}</b-nav-item>
</ul>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question