vue的小练习-翻转单词

先将字符串转成数组,用reverse()翻转数组,再转成字符串

html 复制代码
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
       <h2> {{string}}</h2>
        <button @click="reverse">逆转世界</button>

    </div>
    <script src="../../vue.js"></script>
    <script>
        const app = new Vue({
            el: '#app',
            data: {
                string:'Hello,world',
            },
            methods:{
                reverse(){
                    //先将字符串转成数组,用reverse()翻转数组,再转成字符串
                    this.string=this.string.split('').reverse().join('')
                }
            }
        })
    </script>
</body>

</html>
相关推荐
小刘不知道叫啥17 小时前
React 源码揭秘 | 合成事件
前端·javascript·react.js
ziyue757517 小时前
vue修改element-ui的默认的class
前端·vue.js·ui
树叶会结冰18 小时前
HTML语义化:当网页会说话
前端·html
冰万森18 小时前
解决 React 项目初始化(npx create-react-app)速度慢的 7 个实用方案
前端·react.js·前端框架
牧羊人_myr18 小时前
Ajax 技术详解
前端
浩男孩18 小时前
🍀封装个 Button 组件,使用 vitest 来测试一下
前端
蓝银草同学18 小时前
阿里 Iconfont 项目丢失?手把手教你将已引用的 SVG 图标下载到本地
前端·icon
布列瑟农的星空18 小时前
重学React —— React事件机制 vs 浏览器事件机制
前端
一小池勺19 小时前
CommonJS
前端·面试