Skip to content

Instantly share code, notes, and snippets.

@revskill10
Created August 1, 2018 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save revskill10/8c3a2b2b69b2655f5c8d9cacfb7b17cd to your computer and use it in GitHub Desktop.
Save revskill10/8c3a2b2b69b2655f5c8d9cacfb7b17cd to your computer and use it in GitHub Desktop.
React vs Vue
class UserView extends React.Component {
constructor(props) {
super(props);
this.state = {
user: undefined
};
fetch(`/api/user/${this.props.userId}`)
.then((res) => res.json())
.then((user) => {
this.setState({ user });
});
},
render() {
const user = this.state.user;
return (
<div>
{ user ? (
<p>User name: {user.name}</p>
) : (
<p>Loading…</p>
) }
</div>
);
}
};
UserView.propTypes = {
userId: PropTypes.number
};
const UserView = {
template: `
<div>
<p v-if="user">User name: {{ user.name }}</p>
<p v-else>Loading...</p>
</div>`,
props: {
userId: {
type: Number,
required: true
}
},
data: () => ({
user: undefined
},
mounted() {
fetch(`/api/user/${this.userId}`)
.then((res) => res.json())
.then((user) => {
this.user = user;
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment