Action with namespace: TypeError: Cannot redefine property
See original GitHub issueWhen use Action with namespace, page will throw “TypeError: Cannot redefine property: …”
Part of codes like blow:
import Vue from 'vue'
import Component, {Getter, Action, namespace } from 'class-component'
const DemoGetter = namespace('demo', Getter)
const DemoAction = namespace('demo', Action)
@Component
export default class Demo extends Vue {
@DemoAction selectCity
@Getter authUser
@DemoGetter city
}
According to my research, after vuex-class defined the actions on vm, vue “initMethods” will define all methods onto vm.
function initMethods (vm, methods) {
var props = vm.$options.props;
console.log('methods: ' +JSON.stringify( methods))
for (var key in methods) {
vm[key] = methods[key] == null ? noop : bind(methods[key], vm);
if (process.env.NODE_ENV !== 'production') {
if (methods[key] == null) {
warn(
"method \"" + key + "\" has an undefined value in the component definition. " +
"Did you reference the function correctly?",
vm
);
}
if (props && hasOwn(props, key)) {
warn(
("method \"" + key + "\" has already been defined as a prop."),
vm
);
}
}
}
}
And then vue-class-component method ‘_init’ may redefine them again, so the error occurred.
Component.prototype._init = function () {
var _this = this;
var keys = Object.getOwnPropertyNames(vm);
if (vm.$options.props) {
for (var key in vm.$options.props) {
if (!vm.hasOwnProperty(key)) {
keys.push(key);
}
}
}
keys.forEach(function (key) {
if (key.charAt(0) !== '_') {
Object.defineProperty(_this, key, {
get: function () { return vm[key]; },
set: function (value) { return vm[key] = value; }
});
}
});
};
Does this have any solution or pr?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:7
- Comments:6 (2 by maintainers)
Top Results From Across the Web
TypeError: can't redefine non-configurable property "x"
The JavaScript exception "can't redefine non-configurable property" occurs when it was attempted to redefine a property, but that property is non-configurable.
Read more >webpack-cli: TypeError: Cannot redefine property: tap
i'm receiving this error whenever i try to run npm run dev npm run development npm WARN config global `--global`, `--local` are deprecated....
Read more >Configuring Jest
The function should either return a path to the module that should be resolved or throw an error if the module can't be...
Read more >Ngrx example - ALCA Profumerie
Actions are dispatched via Store in NgRx and observed by NgRx's Reducers and Effects. ... Angular Universal TypeError: Cannot redefine property: [email ...
Read more >Project Configuration File Format - Gerrit Code Review
The refs/meta/config namespace; Property inheritance; The file project.config ... You can also redefine the text and behavior of the built in label types ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Fixed via vue-class-component v6.1.0
@ktsn Thank you!