3

this is my first steps in Vue 2 + bootstrap-vue, and I'm trying to figure out how to dynamically change the name of an attribute, so that at a small screen resolution the tooltip changes its position.

JS code below works fine, but tooltip not changing his position =( Please help me improve my mistake;

.pug

enter image description here enter image description here

JS

'use strict';

import Vue from 'vue';
import BootstrapVue from 'bootstrap-vue';

document.addEventListener("DOMContentLoaded", function () {
    Vue.use(BootstrapVue);
    new Vue({
        el: '#freshbroccoli',
        data: {
            windowWidth: null,
            position: this.windowWidth >= 480 ? 'left' : 'bottom'
        },
        mounted() {
            this.$nextTick(function () {
                window.addEventListener('resize', this.getWindowWidth);
                this.getWindowWidth();
            });
        },
        methods: {
            getWindowWidth() {
                this.windowWidth = document.documentElement.clientWidth;
                console.log('this.windowWidth >= 480 ? \'left\' : \'bottom\'', this.windowWidth >= 480 ? 'left' : 'bottom', '\n', this.windowWidth);
            }
        },
        beforeDestroy() {
            window.removeEventListener('resize', this.getWindowWidth);
        }
    });
});

Browser - Chrome

enter image description here

Browser console - Chrome

enter image description here

2 Answers 2

1

Edit: my old answer assumed that was a v-b-tooltip was a component and not a directive.

From what I can tell, using a variable in a directive isn't supported. One solution would be to use vue-popper since you can update its options dynamically. Bootstrap uses Popper under the hood for its tooltips, so you wouldn't be introducing new technologies this way.

Sign up to request clarification or add additional context in comments.

1 Comment

v-b-tooltip is a directive, not a component. OP is trying to add a dynamic modifier to a directive.
1

For Bootstrap-Vue tooltip there is parameter placement, so code could look like this:

<b-btn title="Title" target="d150" :placement="position">My btn</b-btn>

More at: https://bootstrap-vue.js.org/docs/components/tooltip

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.