<!DOCTYPE html>
<html lang="en">

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

<body>
  <div id="app" class="container">
    <input type="text" class="form-control" v-model="text" style="width: 300px;" placeholder="請輸入文字">
    <button class="btn btn-primary mt-1" v-on:click="reverseText()">反轉字串</button>
    <div class="mt-3">
      {{ newText }}
    </div>
  </div>
</body>

</html>
var app = new Vue({
  el: "#app",
  data: {
    text: "",
    newText: ""
  },
  methods: {
    reverseText: function() {
      this.newText = this.text
        .split("")
        .reverse()
        .join("");
      // 這裡的 this 指向 app
    }
  }
});

External CSS

  1. https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css

External JavaScript

  1. https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.10/vue.min.js