user() {
return new Proxy(this.$store.state.user, {
set: (target, prop, value) => {
this.$store.commit('updateUser', { [prop]: value });
return true;
},
});
},
updateUser(state, payload) {
Object.assign(state.user, payload);
},
import { Provider } from "mobx-react";
ReactDOM.render(<Provider store={store}>
<App />
</Provider>, document.getElementById('root'));
import { inject } from "mobx-react";
import React, { Component } from 'react';
import { inject } from "mobx-react";
@inject("store")
class Form extends Component {
render() {
return (
<form className="form">
<select>
<option></option>
</select>
</form>
);
}
}
export default Form;
import React from "react";
import { inject } from "mobx-react";
const App = () => {
return <div className="App">Hello World!</div>;
};
export default inject("store")(App);
<button onClick={() => this.props.store.getUsers()}></button>
И, насколько я понимаю, нужно обернуть вызываемую функцию в стрелочную функцию, то есть: () =>
, если нужный метод находится за пределами текущего файла. В твоем случае — да.const { getUsers } = this.props.store;
// какой-то код
return <button onClick={() => getUsers()}></button>;
};
someFunction = () => {
const {sms} = this.state;
sms.disabled = true;
this.setState({sms});
}
someFunction = () => {
this.setState({sms: {...this.state.sms, disabled: true}});
}
someFunction = () => {
this.setState(prevState=>({sms: {...prevState.sms, disabled: true}}));
}
async function data() {
return fetch("https://jsonplaceholder.typicode.com/users")
.then(response => response.json())
.then(response => JSON.stringify(response))
};
async function setHTML() {
document.getElementById("app").innerHTML = await data();
}
setHTML();
img(
v-if="active",
:src="require(`@/assets/img/very-long-img-name${i + 1}.gif`)",
alt="")
methods: {
someFunc() {
const vm = this
// _ = lodash
_.each([1,2,3], function(...args) {
// this == function(){}
// vm == vue
})
}
}
<template>
<div>
<li v-bind:class="{ active: isActive }" @click="setActive(false)"></li>
<li v-bind:class="{ active: isActive }" @click="setActive(false)"></li>
<li v-bind:class="{ active: isActive }" @click="setActive(false)"></li>
<li v-bind:class="{ active: isActive }" @click="setActive(false)"></li>
</div>
</template>
<script>
...
setActive: function(active){
this.isActive = active;
}
</script>