Node.js/nuxt:修订间差异

来自康健生活
Kangkk​(留言 | 贡献)
Kangkk​(留言 | 贡献)
 
(未显示同一用户的8个中间版本)
第47行: 第47行:
{| class="wikitable"
{| class="wikitable"
|-
|-
| [[/传值|传值]] || [[/路由|路由]] || [[/跨域|跨域]] || [[/token|token]]
| [[/传值|传值]] || [[/路由|路由]] || [[/跨域|跨域]] || [[/token|token]] || [[/代码打包|代码打包]]
|-
|-
| [[/全局变量|全局变量]] || [[/生命周期|生命周期]] || [[/session|session]] || [[/css module|css module]]
| [[/全局变量|全局变量]] || [[/生命周期|生命周期]] || [[/session|session]] || [[/css module|css module]]
|-
|-
| [[/导入css样式|导入css样式]] || 示例 || 示例
| [[/导入css样式|导入css样式]] || [[/其他|其他]] || [[/骨架屏|骨架屏]] || [[/组件加载方式|组件加载方式]]
|}
|}


第141行: 第141行:
     }
     }
}</syntaxhighlight>
}</syntaxhighlight>
* omputed property "fileList" was assigned to but it has no setter.
*: <syntaxhighlight lang="javascript">
fileList: {
  get () {
    return this.$store.state.file.fileList;
  },
  set (val) {
    this.$store.state.file.fileList = val;
  }
}
</syntaxhighlight>
* client.js?06a0:97 Error: [vuex] do not mutate vuex store state outside mutation handlers.
*: 不能直接修改 state,原码:
*: <syntaxhighlight lang="javascript">
computed: {
  fileList: {
    get() {
        return this.$store.state.file.fileList
    },
    set(fileItem) {
        this.$store.dispatch('file/addFile', fileItem)
    }
  }
},</syntaxhighlight>
*: 修改如下
*: <syntaxhighlight lang="javascript">
computed: {
  fileList: {
    get() {
        return this.$store.state.file.fileList.slice()
    },
    set(fileItem) {
        this.$store.dispatch('file/addFile', fileItem)
    }
  }
},</syntaxhighlight>
* Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's value. Prop being mutated: "fileList"
:* 原码
:* <syntaxhighlight lang="javascript">
mounted() {
  Object.assign(this, this.$store.state.file)
  this.fetchResourceResTagRecom('cs');
},</syntaxhighlight>
:* <syntaxhighlight lang="javascript">
mounted() {
  Object.assign({}, this, this.$store.state.file)
  this.fetchResourceResTagRecom('cs');
},</syntaxhighlight>