Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vue.js Vue样式(背景图像)绑定不反应_Vue.js_Nuxt.js_Computed Properties_Computed Style - Fatal编程技术网

Vue.js Vue样式(背景图像)绑定不反应

Vue.js Vue样式(背景图像)绑定不反应,vue.js,nuxt.js,computed-properties,computed-style,Vue.js,Nuxt.js,Computed Properties,Computed Style,我想在不刷新的情况下根据所选语言更改网站的某些部分。所有这些都有效,但我尝试了多种方法在不刷新站点语言更改(i18n)的情况下动态绑定背景图像。但是没有成功 <div :style="{'background-image' : mainBackground}"> test div </div> 但在通过下拉菜单更改站点语言后,所有其他元素src将更新为使用所选语言图像文件但只有此背景路径未更新。此外,还会删除元素本身的样式属性。我不明白为什

我想在不刷新的情况下根据所选语言更改网站的某些部分。所有这些都有效,但我尝试了多种方法在不刷新站点语言更改(i18n)的情况下动态绑定背景图像。但是没有成功

<div :style="{'background-image' : mainBackground}">
     test div
</div>
但在通过下拉菜单更改站点语言后,所有其他元素src将更新为使用所选语言图像文件但只有此背景路径未更新。此外,还会删除元素本身的样式属性。我不明白为什么这个解决方案不能正常工作。还将
mainBackground
计算到div元素中。返回的链接将根据语言进行更新

mainBackground(){
    return this.isTurkishSite ? 'url(/images/home/home_bg_main_tr.jpg);' : 'url(/images/home/home_bg_main.jpg);'
}
我使用类绑定解决了这个问题。土耳其语为1级,其他语言为主语。并在条件类绑定中使用它们。解决方案:

:class="[isTurkishSite ? 'bg-turkish' : '']"

它不起作用,因为您在url()指令的末尾放了分号,在Vue的对象表示法中设置的css规则不需要分号:)

我已经测试并工作了。非常感谢。但在第一次加载中,它与结尾分号一起工作。这就是为什么我不能得到什么是错误的)无论如何,正如你提到的,没有分号,它可以在第一次加载和以后的更改中工作。