您好,欢迎来到榕意旅游网。
搜索
您的当前位置:首页Vue3 做了哪些优化

Vue3 做了哪些优化

来源:榕意旅游网
  • 使用 setup 修改了之前 export default 的写法
<template>
<h1>{{ msg }}</h1>
</template>

<script setup>
const msg = 'hello'
</script>

ref

<template>
<h1>{{ msg }}</h1>
</template>

<script setup>
    import { ref } from 'vue'  
	const msg = ref('hello')
</script>

props

// Hello.vue
<template>
<h1>{{ props.msg }}</h1>
</template>

<script setup>
    import { defineProps } from 'vue'  
	const props = defineProps({
        msg: String
    })
</script>

子组件引入

<template>
<Hello	:msg="msg"></Hello>
</template>

<script setup>
    import { ref } from 'vue'
    import Hello from './Hello.vue'
	const msg = ref('vue3')
</script>
  • style 变量动态注入
<template>
	<div>
        <h1>这是一段红色的文字</h1>	
        <button	@click="color = 'green'"> 点击改变文字颜色</button>
    </div>	
</template>

<script setup>
    import {ref} from 'vue'
    const color = ref('red')
</script>

<style>
    h1 {
     color: v-bind(color)   
    }
</style>

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- nryq.cn 版权所有

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务