4

In a SinglePageApp, I need to use a <button> tag rather than an <a> tag 5 I am using UKit

the <a> tag would be :

<a type="button" class="uk-button uk-button-link" href="#events"><events</a>

But writing the tag this way , does not work

 <button @click="location.href='{{ url('events') }}'" class="uk-button uk-button-link">EVENTS</button>

note : I see an ESLint error .. [js] ';' expected

2 Answers 2

3

@webnoob answer is correct , however it seems that it's not working in a single page application : I get a scopelocation undefined error..

SO I am using a method :

      <button @click="goToEvents()" class="uk-button uk-button-link">EVENTS</button>

and

methods: {
    goToEvents: function () {
        location.href='#events'
    }
},
Sign up to request clarification or add additional context in comments.

Comments

0

To do an onclick with Vue, you would do it like this:

<button v-on:click="location.href=url('events')" class="uk-button uk-button-link">EVENTS</button>

You can also use @click="location.href=url('events')"

Take a look at Vue Event Binding for more information.

If you're within a form and don't want the form to be posted as well, you would need to also add in .prevent so it would become v-on:click.prevent="url('events')"

You only use {{ }} (mustache's) when you're rendering content i.e text. When you're within an attribute which you want to use dynamic values in, you would prefix the attribute with : so, for instance, if you wanted to add some dynamic text in a data attribute, it would become :data-something="myDataProp"

2 Comments

just tried it ... not working Is it because I am in a singlepage app scope.location is undefined
Yes, I almost suggested you wrapping the redirect into a method but it wasn't really in scope of the question. Glad you got it working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.