2017-09-16 107 views
2

这是我在第一步的Vue 2 + 引导-VUE,我试图找出如何动态地更改属性的名称,以便在工具提示改变其位置的小屏幕分辨率。Vue的2 +引导-VUE - 动态属性

下面

JS代码工作正常,但提示无法改变他的位置=( 请帮助我提高我的错误;

.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); 
     } 
    }); 
}); 

浏览器 - 铬

enter image description here

浏览器控制台 - 铬

enter image description here

回答

1

编辑:我的老回答假设是v-b-tooltip是一个组件,而不是一个指令。

从我可以告诉,不支持在指令中使用变量。一种解决方案是使用vue-popper,因为您可以动态更新其选项。 Bootstrap使用Popper作为其工具提示,因此您不会以这种方式引入新技术。

+0

v-b-tooltip是一个指令,而不是组件。 OP正试图为指令添加一个动态修饰符。 – Bert

+0

@Bert啊,谢谢。我会更新我的答案。 – Franey