2
这是我在第一步的Vue 2 + 引导-VUE,我试图找出如何动态地更改属性的名称,以便在工具提示改变其位置的小屏幕分辨率。Vue的2 +引导-VUE - 动态属性
下面JS代码工作正常,但提示无法改变他的位置=( 请帮助我提高我的错误;
.pug
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);
}
});
});
浏览器 - 铬
浏览器控制台 - 铬
v-b-tooltip是一个指令,而不是组件。 OP正试图为指令添加一个动态修饰符。 – Bert
@Bert啊,谢谢。我会更新我的答案。 – Franey