这是一个Vue.js和Vuex相关的问题。
我正在构建一个应用程序,其中显示住宅列表(ul -> li -> a),同时显示这些插图在插图中的位置,通过 SVG 解决(活动元素是路径和多边形)。如果它只是一个元素,我可以只使用 css 来显示活动状态,但是因为同时有两个活动元素,我需要一个事件。
以前我通过给存储在 Vuex 中的住所提供一个hasFocus: false值来解决这个问题,我会在 mouseenter/focus 时将其更改为true,在 mouseout/focusout 时将其更改为 false。有了它,我可以添加/删除我添加活动状态 css的类有焦点。我现在已经重做数据存储以使用Vuex ORM,之后在执行突变时我看到更严重的帧速率下降。
有没有比在 Vuex (ORM) 对象模型中使用值更好的方法呢?
一些代码:
在 Vuex 中:
residences: [
{
id: 1,
hasFocus: false,
[…] // Other values, not relevant to this question
},
{
id: 2,
hasFocus: false
},
…
…
],
在 ResidenceItem.vue 中:
<router-link
[…]
v-bind:class="{
'has-focus': residence.hasFocus === true,
}"
@mouseenter.native.stop="toggleFocus(true)"
@mouseout.native.stop="toggleFocus(false)"
@focus.native.stop="toggleFocus(true)"
@focusout.native.stop="toggleFocus(false)"
[…]
>
// Content
</router-link>
[…]
props: {
id: {
required: true,
},
},
methods: {
toggleFocus(focus) {
Residence.update({
where: this.id,
data: {
hasFocus: focus,
},
});
},
},