Code Demo
小于 1 分钟
Demo
Demo
Demo
<h1>VuePress Theme Hope</h1>
<p>is <span id="very">very</span> powerful!</p>
document.querySelector("#very").addEventListener("click", () => {
alert("Very powerful");
});
span {
color: red;
}
A Vue Composition Demo
<template>
<div class="box">
<code>vuepress-theme-hope</code> is
<span @click="handler">{{ message }}</span
>!
</div>
</template>
<script>
const { ref } = Vue;
export default {
setup() {
const message = ref("powerful");
const handler = () => {
message.value = "very " + message.value;
};
return {
message,
handler,
};
},
};
</script>
<style>
.box span {
color: red;
}
</style>
A Vue Option Demo
<template>
<div class="box">
<code>vuepress-theme-hope</code> is
<span @click="handler">{{ message }}</span
>!
</div>
</template>
<script>
export default {
data: () => ({ message: "powerful" }),
methods: {
handler() {
this.message = "very " + this.message;
},
},
};
</script>
<style>
.box span {
color: red;
}
</style>
A function-based React Demo
const { useState } = React;
export default () => {
const [message, setMessage] = useState(" powerful");
const handler = () => {
setMessage(` very${message}`);
};
return (
<div className="box">
<code>vuepress-theme-hope</code> is
<span id="powerful" onClick={handler}>
{message}
</span>!
</div>
);
};
.box #powerful {
color: blue;
}
A class-based React Demo
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = { message: " powerful" };
}
handler() {
this.setState((state) => ({
message: ` very${state.message}`,
}));
}
render() {
return (
<div className="box">
<code>vuepress-theme-hope</code> is
<span id="powerful" onClick={this.handler.bind(this)}>
{this.state.message}!
</span>
</div>
);
}
}
.box #powerful {
color: blue;
}
A demo using language not supported by browsers
# Title
is very powerful!
const message: string = "VuePress Theme Hope";
document.querySelector("h1").innerHTML = message;
h1 {
font-style: italic;
+ p {
color: red;
}
}