vue

安装

  1. npm 安装 首先使用npm init新建一个node js项目
    之后输入一些项目信息即可
    image
  2. 根据文档安装vue
    image
  3. 根据文档引入vue
    image
    image

常用指令

首先新建一个vue实例

和vue2 语法不同 变成根据对象创建实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <script src="node_modules/vue/dist/vue.global.prod.js"></script>
</head>
<body>
    <div id="app">

    </div>
</body>

    <script>
        const Counter = {
            data() {
                return {
                }
            }
        }

        Vue.createApp(Counter).mount('#app');
    </script>

</html>

双向绑定和单项绑定

双向绑定指 标签与数据相联系 两者修改都会受到影响
单项绑定是执元素和数据绑定 只有数据改变标签才会变 标签改变数据不会变

v-html

将元素按html输出

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <script src="node_modules/vue/dist/vue.global.prod.js"></script>
</head>
<body>
    <div id="app">
        <span v-html="h">

        </span>
    </div>
</body>

    <script>
        const Counter = {
            data() {
                return {
                    h: '<h1>Hello world</h1>'   
                }
            }
        }

        Vue.createApp(Counter).mount('#app');
    </script>

</html>

v-text

按文本输出

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <script src="node_modules/vue/dist/vue.global.prod.js"></script>
</head>
<body>
    <div id="app">
        <span v-text="h">

        </span>
    </div>
</body>

    <script>
        const Counter = {
            data() {
                return {
                    h: '<h1>Hello world</h1>'   
                }
            }
        }

        Vue.createApp(Counter).mount('#app');
    </script>

</html>

v-bind

将元素属性绑定

posted @   RainbowMagic  阅读(28)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示