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