Vue3 Mustache構文内にfilterを使用するサンプル

概要
filterを使用するには、「computed」を使用します。
使用例
filterを使用して変数「val」を大文字に変換して表示します
サンプルコード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>filterサンプル</title>
<!-- semantic.css -->
<link rel="stylesheet" type="text/css"
href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.css">
<script src="https://unpkg.com/vue@next"></script>
</head>
<style>
body>.grid {
height: 100%;
}
</style>
<body>
<div id="app" class="ui middle aligned center aligned grid">
<div class="column">
<h2 class="ui gray header">{{foo}}</h2>
</div>
</div>
<script>
const cft = {
data() {
return {
val: 'filter'
}
},
computed: {
foo() {
return this.val.toUpperCase()
}
}
}
Vue.createApp(cft).mount('#app')
</script>
</body>
</html>
<!DOCTYPE html> <html lang="ja"> <head> <meta charset="utf-8"> <title>filterサンプル</title> <!-- semantic.css --> <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.css"> <script src="https://unpkg.com/vue@next"></script> </head> <style> body>.grid { height: 100%; } </style> <body> <div id="app" class="ui middle aligned center aligned grid"> <div class="column"> <h2 class="ui gray header">{{foo}}</h2> </div> </div> <script> const cft = { data() { return { val: 'filter' } }, computed: { foo() { return this.val.toUpperCase() } } } Vue.createApp(cft).mount('#app') </script> </body> </html>
<!DOCTYPE html>
<html lang="ja">

<head>
  <meta charset="utf-8">
  <title>filterサンプル</title>
  <!-- semantic.css  -->
  <link rel="stylesheet" type="text/css"
    href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.css">
  <script src="https://unpkg.com/vue@next"></script>

</head>
<style>
  body>.grid {
    height: 100%;
  }
</style>

<body>
  <div id="app" class="ui middle aligned center aligned grid">

    <div class="column">

      <h2 class="ui gray header">{{foo}}</h2>

    </div>

  </div>
  <script>

    const cft = {
      data() {
        return {
          val: 'filter'
        }
      },
      computed: {
        foo() {
          return this.val.toUpperCase()
        }
      }
    }

    Vue.createApp(cft).mount('#app')

  </script>
</body>

</html>

 

IT

Posted by arkgame