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 } },