Heim > Fragen und Antworten > Hauptteil
P粉3005417982023-08-31 16:51:55
您原来的logoTop
计算属性可以在样式绑定中用于设置v-img
的top
位置:
<template> <v-img :style="{ top: logoTop }" ... /> </template> <script> export default { computed: { logoTop() { switch (this.$vuetify.breakpoint.name) { case 'xl': return "-4%" case 'lg': return "-6%" case 'md': return "-8%" case 'sm': return "-8%" case 'xs': return 0 default: return "-4%" } }, } } </script>
P粉4623289042023-08-31 14:24:05
switch
不返回任何内容。你应该像这样使用一个变量
logoTop() { let topProperty; switch (this.$vuetify.breakpoint.name) { case 'xl': topProperty = 400; break; case 'lg': case 'md': topProperty = 300; break; case 'sm': topProperty = 200; break; case 'xs': topProperty = 0; break; default: topProperty = 400; } return { "--top-property" : topProperty } },