官网课程给的示例结构如下
.
├── assets
│ ├── images
│ │ ├── socks_blue.jpg
│ │ └── socks_green.jpg
│ └── styles.css
├── index.html
└── main.js
样式我们不用管,只需要管这两个
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<!-- Import Styles -->
<link rel="stylesheet" href="./assets/styles.css" />
<!-- Import Vue.js -->
<script src="https://unpkg.com/vue@3.0.0-beta.12/dist/vue.global.js"></script>
</head>
<body>
<div id="app">
<img v-bind:src="image">
<h1>{{ product }}</h1>
<a :href="url">Made by Vue Mastery</a>
</div>
<!-- Import App -->
<script src="./main.js"></script>
<!-- Mount App -->
<script>
const mountedApp = app.mount('#app')
</script>
</body>
</html>
<img v-bind:src="image">
是调用图片
<h1>{{ product }}</h1>
调用数据
<a :href="url">Made by Vue Mastery</a>
链接
注意都要放在app的div下
main.js如下:
const app = Vue.createApp({
data(){
return{
product: 'Boots',
description: 'this is a socket',
image: './assets/images/socks_green.jpg',
url: 'https://www.vuemastery.com'
}
}
})