首页 > 解决方案 > 测试 Vue.js (^2.5.*) 组件时如何处理有关 prop 发生突变的警告消息

问题描述

在测试使用 Vue utils 安装的组件时,我遇到以下错误消息:

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: <prop name>

标签: testingvue.jsvuejs2

解决方案


挂载要测试的组件时,为防止错误消息显示在控制台中,请将sync选项传递给 false 给mount函数。另请参阅https://vue-test-utils.vuejs.org/api/options.html#sync


推荐阅读