Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
  <div id="app">
  
    <!-- 直接寫入HTML裡 -->
    <div class="box" :style="{backgroundColor: 'orange'}"></div>
    <div class="box" :style="{backgroundImage: 'url(' + img + ')' }"></div>
    <hr>
    
    <!-- 取用Vue Data的值 -->
    <div class="box" :style="styleObject1"></div>
    
    <hr>
    <!-- 陣列方式,裡面插入多個物件 -->
    <div class="box" :style="[{backgroundColor: 'orange'}, {borderWidth: '3px'}]"></div>
    <div class="box" :style="[styleObject1, styleObject2]"></div>
  </div>
  
  
  <!-- development version, includes helpful console warnings -->
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</body>
</html>
 
new Vue({
  el: '#app',
  data: {
      img: 'https://fakeimg.pl/100x100/?text=Hello',
      styleObject1: {
        // 使用駝峰式命名
        backgroundColor: 'red',
        borderWidth: '10px'
      },
      styleObject2: {
        boxShadow: '3px 3px 5px rgba(0, 0, 0, 0.16)'
      }
  },
});
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers