Vue
類似於 React.js 或 Angular 之前端框架
建立專案
yarn global add @vue/cli
vue create my-project基本結構
App.vue
<template>
...html
</template>
<script>
export default {
name: "App", // component 的名稱
methods: {
//onclick 之類 dom 觸發的方法都寫這
},
data: () => ({
//類似於 react state
})
};
</script>
<style>
#app {
// style 寫這
}
</style>main.js 寫一些 初始化的行為
Ref
存取某個元素時使用
之後用以下存取
也可以在 child compoent 加上 ref,之後用 this.$refs 存取到後可改變 child 內的 state 或 call child function
綁定 dom 觸發事件
v-on:click 可改為 @click
Render List (類似 react map render)
Watch prop
Template
類似於 react 的
可以當作空的 html tag
https://vuejs.org/v2/guide/list.html#v-for-on-a-lt-template-gt
Last updated
Was this helpful?