【发布时间】:2018-09-27 03:47:33
【问题描述】:
我试图在属性style 中使用组件变量,但这样做时会出现编译错误。这里有什么问题?
模块构建失败:SyntaxError: Unexpected token (1:427)
<template>
<div>
<!-- THe below is valid -->
<img v-bind:src="$IMG_PATH + '/carousel1.jpeg'"/>
<!-- The below wont compile: has syntax errors? -->
<p v-bind:style="background-image: url('$IMG_PATH + \'/carousel1.jpeg\''));">Foo</p>
</div>
</template>
<script>
Vue.prototype.$IMG_PATH = './foo/img'
export default {
...
}
</script>
</style>
【问题讨论】:
-
从 CSS 方面看,应该是
backgrond-image: url(),而不是background-image(url()) -
@Vucko 感谢这是问题的一部分,但我仍然遇到编译器错误。
标签: vue.js vue-component