Created
August 1, 2018 12:22
-
-
Save revskill10/8c3a2b2b69b2655f5c8d9cacfb7b17cd to your computer and use it in GitHub Desktop.
React vs Vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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