1- import  {  toRefs  }  from  'composition-api' 
1+ import  {  toRefs ,   watch  }  from  'composition-api' 
22
33export  default  function  useValue  ( props ,  context ,  dependencies ) 
44{ 
5-  const  {  value : baseValue ,  modelValue,  falseValue }  =  toRefs ( props ) 
5+  const  {  value : baseValue ,  modelValue,  falseValue,  trueValue  }  =  toRefs ( props ) 
66
77 /* istanbul ignore next */ 
8-  const  value  =  context . expose  !==  undefined  ? modelValue  : baseValue 
8+  const  inputValue  =  context . expose  !==  undefined  ? modelValue  : baseValue 
99
1010 // =============== METHODS ============== 
1111
@@ -16,13 +16,23 @@ export default function useValue (props, context, dependencies)
1616 context . emit ( 'change' ,  val ) 
1717 } 
1818
19+  const  handleInput  =  ( val )  =>  { 
20+  update ( val . target . checked  ? trueValue . value  : falseValue . value ) 
21+  } 
22+ 
1923 // ================ HOOKS =============== 
2024
21-  if  ( [ null ,  undefined ] . indexOf ( value . value )  !==  - 1 )  { 
25+  if  ( [ null ,  undefined ,   false ,   0 ,   '0' ,   'off' ] . indexOf ( inputValue . value )  !==  - 1 )  { 
2226 update ( falseValue . value ) 
2327 } 
2428
29+  if  ( [ true ,  1 ,  '1' ,  'on' ] . indexOf ( inputValue . value )  !==  - 1 )  { 
30+  update ( trueValue . value ) 
31+  } 
32+ 
2533 return  { 
26-  value, 
34+  inputValue, 
35+  update, 
36+  handleInput, 
2737 } 
2838} 
0 commit comments