Categories
Vue Answers

How to handle mouse button down event with Vue.js?

Sometimes, we want to handle mouse button down event with Vue.js.

In this article, we’ll look at how to handle mouse button down event with Vue.js.

How to handle mouse button down event with Vue.js?

To handle mouse button down event with Vue.js, we can listen to the mousedown event.

For instance, we write

<template>
  <div>
    <button @mousedown="mouseDown">mouse down</button>
  </div>
</template>

to listen to the mousedown event with @mousedown.

We run the mouseDown method when we press down the mouse button when our cursor is on the button.

Conclusion

To handle mouse button down event with Vue.js, we can listen to the mousedown event.

Categories
Vue Answers

How to use mask in a Vue.js Vuetify text field?

Sometimes, we want to use mask in a Vue.js Vuetify text field.

In this article, we’ll look at how to use mask in a Vue.js Vuetify text field.

How to use mask in a Vue.js Vuetify text field?

To use mask in a Vue.js Vuetify text field, we can use the v-mask package.

To install it, we run

npm install v-mask

Then in main.js, we register the directive globally with

import { VueMaskDirective } from "v-mask";
Vue.directive("mask", VueMaskDirective);

Then we use it with v-text-field by writing

<template>
  <div>
    <v-text-field
      v-mask="'###.###.###-##'"
      :value="currentValue"
      @input="handleInput"
    />
  </div>
</template>

We set v-mask to the mask we want.

Conclusion

To use mask in a Vue.js Vuetify text field, we can use the v-mask package.

Categories
Vue Answers

How to import Vue.js components with Webpack?

Sometimes, we want to import Vue.js components with Webpack.

In this article, we’ll look at how to import Vue.js components with Webpack.

How to import Vue.js components with Webpack?

To import Vue.js components with Webpack, we should register it by putting it into the components property object.

For instance, we write

<template>
  <top-bar></top-bar>
  <div class="message">{{ message }}</div>
</template>

<script>
import TopBar from "./top-bar";

export default {
  components: {
    TopBar,
  },
  data() {
    return {
      message: "Hello World",
    };
  },
};
</script>

to import the TopBar component with

import TopBar from "./top-bar";

Then we register the TopBar component with

components: {
  TopBar,
}

And then we can use it in our template with

<top-bar></top-bar>

Conclusion

To import Vue.js components with Webpack, we should register it by putting it into the components property object.

Categories
Vue Answers

How to disable source maps in production for a Vue.js app?

Sometimes, we want to disable source maps in production for a Vue.js app.

In this article, we’ll look at how to disable source maps in production for a Vue.js app.

How to disable source maps in production for a Vue.js app?

To disable source maps in production for a Vue.js app, we can set the productionSourceMap option to false in vue.config.js.

For instance, we write

module.exports = {
  productionSourceMap: false,
};

to set productionSourceMap to false.

Conclusion

To disable source maps in production for a Vue.js app, we can set the productionSourceMap option to false in vue.config.js.

Categories
Vue Answers

How to fix ‘Vue is not defined’ with Vue.js?

Sometimes, we want to fix ‘Vue is not defined’ with Vue.js.

In this article, we’ll look at how to fix ‘Vue is not defined’ with Vue.js.

How to fix ‘Vue is not defined’ with Vue.js?

To fix ‘Vue is not defined’ with Vue.js, we add the Vue script before we create Vue instance.

For instance, we write

<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>

Then we write

<script>
  const demo = new Vue({
    el: "#app",
    data: {
      message: "Hello!",
    },
  });
</script>

to create a Vue instance after the Vue script tag.

Conclusion

To fix ‘Vue is not defined’ with Vue.js, we add the Vue script before we create Vue instance.